Skip to content

Commit 1079360

Browse files
authored
Add Field::with_dict_is_ordered (#6885)
1 parent 54dccad commit 1079360

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

arrow-schema/src/field.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,19 @@ impl Field {
426426
}
427427

428428
/// Returns whether this `Field`'s dictionary is ordered, if this is a dictionary type.
429+
///
430+
/// # Example
431+
/// ```
432+
/// # use arrow_schema::{DataType, Field};
433+
/// // non dictionaries do not have a dict is ordered flat
434+
/// let field = Field::new("c1", DataType::Int64, false);
435+
/// assert_eq!(field.dict_is_ordered(), None);
436+
/// // by default dictionary is not ordered
437+
/// let field = Field::new("c1", DataType::Dictionary(Box::new(DataType::Int64), Box::new(DataType::Utf8)), false);
438+
/// assert_eq!(field.dict_is_ordered(), Some(false));
439+
/// let field = field.with_dict_is_ordered(true);
440+
/// assert_eq!(field.dict_is_ordered(), Some(true));
441+
/// ```
429442
#[inline]
430443
pub const fn dict_is_ordered(&self) -> Option<bool> {
431444
match self.data_type {
@@ -434,6 +447,18 @@ impl Field {
434447
}
435448
}
436449

450+
/// Set the is ordered field for this `Field`, if it is a dictionary.
451+
///
452+
/// Does nothing if this is not a dictionary type.
453+
///
454+
/// See [`Field::dict_is_ordered`] for more information.
455+
pub fn with_dict_is_ordered(mut self, dict_is_ordered: bool) -> Self {
456+
if matches!(self.data_type, DataType::Dictionary(_, _)) {
457+
self.dict_is_ordered = dict_is_ordered;
458+
};
459+
self
460+
}
461+
437462
/// Merge this field into self if it is compatible.
438463
///
439464
/// Struct fields are merged recursively.

0 commit comments

Comments
 (0)