@@ -426,6 +426,19 @@ impl Field {
426
426
}
427
427
428
428
/// 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
+ /// ```
429
442
#[ inline]
430
443
pub const fn dict_is_ordered ( & self ) -> Option < bool > {
431
444
match self . data_type {
@@ -434,6 +447,18 @@ impl Field {
434
447
}
435
448
}
436
449
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
+
437
462
/// Merge this field into self if it is compatible.
438
463
///
439
464
/// Struct fields are merged recursively.
0 commit comments