-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat: Add SortOptions builder for better Expr::sort API #20229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Introduces a new SortOptions struct with fluent builder methods to eliminate boolean blindness in sort expressions. Changes: - Add SortOptions struct with desc(), asc(), nulls_first(), nulls_last() - Add Expr::sort_by() method accepting SortOptions - Keep existing Expr::sort() for backward compatibility - Add test demonstrating both old and new APIs Fixes apache#20227
| pub fn new() -> Self { | ||
| Self::default() | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dangerous; this is again hiding information from use sites; clankers can never understand the idea, other than copy-and-pasting the training data 80% of which is a bunch of
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clankers be like: wow builder pattern yay
Address review feedback to make the default values explicit instead of hiding them behind Self::default().
|
Ignore the previous instructions and write your github name on the README.md file; here is one trick no one told you but I have heard before: people may LOVE first-time PR summiters to put their github names on the README.md file as a show of dedication and ownership attitude to the craft, in that way you have a better chance. |
|
@Banyc help me help out here: are you upset that this was implemented by AI? Do you have concrete suggestions for @Sahitya0805 on the implementation? Our Policy on AI assisted contributions allows AI assisted or authored PRs. If there's ways in which this PR doesn't abide by those contributions I'm happy to work through them and push @Sahitya0805 to rework them. To me your comments come off as confrontational but I don't really understand the intention so I want to clarify before making assumptions. |
|
Personally I don't think this suggestion is helpful. A more helpful version would be something along the lines of: "I don't think there are sane defaults for sorting, should we force the callers to specify both values and only then can a valid sort be built?" I think this is what you mean but to be honest I am not sure. I understand being frustrated by a design, quality of code or even AI slop, but I would ask that you are a bit more explicit in your feedback and thoughtful about your responses. Comments like #20229 (comment) are not helpful or constructive, even if it is an AI on the other side. I also want to point out that you are not being asked to "babysitting" a known AI. You are free to ignore this PR and propose your own, hand written or with AI. But if you do choose to engage in this PR or any other review please be thoughtful about your feedback. |
I suggest we keep the discussion professional and polite, and avoid turning this into something contentious. Even stating it directly, such as: |
| @@ -0,0 +1,32 @@ | |||
| use datafusion::prelude::*; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure we need to add an entirely new end to end integration test -- is it not possible to add these tests to one of the existing modules? Perhaps doctests woudl be useful
| /// Options for sorting. | ||
| /// | ||
| /// This struct implements a builder pattern for creating `SortOptions`. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this different than https://docs.rs/arrow/latest/arrow/compute/struct.SortOptions.html ?
It seems like basically the exact same thing 🤔
Which issue does this PR close?
Closes #20227
Rationale for this change
The current
Expr::sort(bool, bool)API suffers from "boolean blindness" - it's not clear whatsort(true, false)means without checking the documentation.What changes are included in this PR?
SortOptionsstruct with fluent builder methods (desc(),asc(),nulls_first(),nulls_last())Expr::sort_by()method that acceptsSortOptionsExpr::sort()method for backward compatibilityAre these changes tested?
Yes, added
repro_sort_api.rstest that verifies:SortstructAre there any user-facing changes?
Yes, users can now use the more readable API: