Skip to content

Conversation

@Sahitya0805
Copy link

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 what sort(true, false) means without checking the documentation.

What changes are included in this PR?

  • Added SortOptions struct with fluent builder methods (desc(), asc(), nulls_first(), nulls_last())
  • Added Expr::sort_by() method that accepts SortOptions
  • Kept existing Expr::sort() method for backward compatibility
  • Added test demonstrating both old and new APIs

Are these changes tested?

Yes, added repro_sort_api.rs test that verifies:

  • Old API still works correctly
  • New API produces correct Sort struct
  • Default options work as expected

Are there any user-facing changes?

Yes, users can now use the more readable API:

// Old API (still supported)
col("foo").sort(true, false)

// New API (recommended)
col("foo").sort_by(SortOptions::new().desc().nulls_first())

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
@github-actions github-actions bot added logical-expr Logical plan and expressions core Core DataFusion crate labels Feb 9, 2026
Comment on lines 14 to 16
pub fn new() -> Self {
Self::default()
}
Copy link

@Banyc Banyc Feb 9, 2026

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

Copy link

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().
@Banyc
Copy link

Banyc commented Feb 9, 2026

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.

@adriangb
Copy link
Contributor

adriangb commented Feb 9, 2026

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate logical-expr Logical plan and expressions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better API for Expr::sort(bool, bool); // acktually BOOL BOOL

3 participants