Skip to content

Commit

Permalink
Add nulls_first() and nulls_last() and more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Sep 24, 2024
1 parent 9f1d298 commit 4f22fd8
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion arrow-schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub mod ffi;
/// # Example creation
/// ```
/// # use arrow_schema::SortOptions;
/// // configure using explicit initialization
/// let options = SortOptions {
/// descending: false,
/// nulls_first: true,
Expand All @@ -55,8 +56,14 @@ pub mod ffi;
/// // Configure using builder APIs
/// let options = SortOptions::default()
/// .desc()
/// .with_nulls_first(true);
/// .nulls_first();
/// assert_eq!(options.to_string(), "DESC NULLS FIRST");
///
/// // configure using explicit field values
/// let options = SortOptions::default()
/// .with_descending(false)
/// .with_nulls_first(false);
/// assert_eq!(options.to_string(), "ASC NULLS LAST");
/// ```
///
/// # Example operations
Expand Down Expand Up @@ -100,17 +107,37 @@ impl SortOptions {
}

/// Set this sort options to sort in descending order
///
/// See [Self::with_descending] to explicitly set the underlying field
pub fn desc(mut self) -> Self {
self.descending = true;
self
}

/// Set this sort options to sort in ascending order
///
/// See [Self::with_descending] to explicitly set the underlying field
pub fn asc(mut self) -> Self {
self.descending = false;
self
}

/// Set this sort options to sort nulls first
///
/// See [Self::with_nulls_first] to explicitly set the underlying field
pub fn nulls_first(mut self) -> Self {
self.nulls_first = true;
self
}

/// Set this sort options to sort nulls last
///
/// See [Self::with_nulls_first] to explicitly set the underlying field
pub fn nulls_last(mut self) -> Self {
self.nulls_first = false;
self
}

/// Set this sort options to sort descending if argument is true
pub fn with_descending(mut self, descending: bool) -> Self {
self.descending = descending;
Expand Down

0 comments on commit 4f22fd8

Please sign in to comment.