Skip to content
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

Add Field::with_dict_is_ordered #6885

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading