Skip to content

Conversation

@alamb
Copy link
Contributor

@alamb alamb commented Sep 23, 2024

Which issue does this PR close?

Related to apache/datafusion#12446

Rationale for this change

While working on apache/datafusion#12562 I found I kept having to do mental gymnastics to remember the default value of SortOptions

I also found creating them was a bit confuisng as if I want to make ASC the default I have to do
descending: false and the double negative was making my head hurt.

What changes are included in this PR?

  1. Add additional documentation
  2. Add builder style APIs that permits configuring an ASC sort with options.asc() rather than descending:false
  3. Update some uses to the new builder style to demonstrate its use

Are there any user-facing changes?

New API and docs, no changes to existing APIs

@github-actions github-actions bot added the arrow Changes to the arrow crate label Sep 23, 2024
descending: true,
nulls_first: false,
},
SortOptions::default().desc().with_nulls_first(false),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is an example of using the new API

Not only is this more concise, I believe the intent is easier to reason about now (asc/desc)

/// ```
///
/// # Example operations
/// It is also possible to negate the sort options using the `!` operator.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found the use of the ! in DataFusion a bit surprising at first

@alamb alamb changed the title Minor: Add additional documentation and builder APIs to SortOptions Add additional documentation and builder APIs to SortOptions Sep 23, 2024
@alamb alamb marked this pull request as ready for review September 23, 2024 14:15
Copy link
Contributor

@etseidl etseidl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @alamb, looks like a nice addition to me. Just one little nit.

Comment on lines 83 to 84
if self.nulls_first {
// purposely don't display default NULLs value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default for nulls_first doesn't seem to be documented, so wouldn't it be clearer to print the value here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think you are right -- it is more consistent even if more verbose

/// let options = SortOptions::default()
/// .desc()
/// .with_nulls_first(true);
/// assert_eq!(options.to_string(), "DESC NULLS FIRST");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// assert_eq!(options.to_string(), "DESC NULLS FIRST");
/// assert_eq!(options.to_string(), "DESC");

If fmt continues to print nothing for the default.

}

/// Set this sort options to sort nulls first if argument is true
pub fn with_nulls_first(mut self, nulls_first: bool) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep this API for sure, but to be consistent with what you propose at apache/datafusion#12595 (nulls_first() / nulls_last() API for PhysicalSortExpr), should we add nulls_first() and nulls_last() here, too?

Copy link
Contributor Author

@alamb alamb Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is a good idea -- added in 4f22fd8

@alamb
Copy link
Contributor Author

alamb commented Sep 24, 2024

Close/reopen to trigger CI

@alamb
Copy link
Contributor Author

alamb commented Sep 24, 2024

integration CI is failing due to #6448

@alamb alamb merged commit 6137e91 into apache:master Sep 25, 2024
@alamb
Copy link
Contributor Author

alamb commented Sep 25, 2024

Thanks again @etseidl and @berkaysynnada for the review

@alamb alamb deleted the alamb/sort_expr_docs branch September 25, 2024 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants