Skip to content

Commit

Permalink
Add Field::with_dict_is_ordered (#6885)
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb authored Dec 18, 2024
1 parent 54dccad commit 1079360
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions arrow-schema/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,19 @@ impl Field {
}

/// Returns whether this `Field`'s dictionary is ordered, if this is a dictionary type.
///
/// # Example
/// ```
/// # use arrow_schema::{DataType, Field};
/// // non dictionaries do not have a dict is ordered flat
/// let field = Field::new("c1", DataType::Int64, false);
/// assert_eq!(field.dict_is_ordered(), None);
/// // by default dictionary is not ordered
/// let field = Field::new("c1", DataType::Dictionary(Box::new(DataType::Int64), Box::new(DataType::Utf8)), false);
/// assert_eq!(field.dict_is_ordered(), Some(false));
/// let field = field.with_dict_is_ordered(true);
/// assert_eq!(field.dict_is_ordered(), Some(true));
/// ```
#[inline]
pub const fn dict_is_ordered(&self) -> Option<bool> {
match self.data_type {
Expand All @@ -434,6 +447,18 @@ impl Field {
}
}

/// Set the is ordered field for this `Field`, if it is a dictionary.
///
/// Does nothing if this is not a dictionary type.
///
/// See [`Field::dict_is_ordered`] for more information.
pub fn with_dict_is_ordered(mut self, dict_is_ordered: bool) -> Self {
if matches!(self.data_type, DataType::Dictionary(_, _)) {
self.dict_is_ordered = dict_is_ordered;
};
self
}

/// Merge this field into self if it is compatible.
///
/// Struct fields are merged recursively.
Expand Down

0 comments on commit 1079360

Please sign in to comment.