Skip to content

Commit

Permalink
Set DICTIONARY_ORDERED flag for FFI_ArrowSchema (#2050)
Browse files Browse the repository at this point in the history
* Set DICTIONARY_ORDERED flag for FFI_ArrowSchema

* Fix clippy
  • Loading branch information
viirya committed Jul 12, 2022
1 parent 742a590 commit a2f223c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
22 changes: 21 additions & 1 deletion arrow/src/datatypes/ffi.rs
Expand Up @@ -288,12 +288,16 @@ impl TryFrom<&Field> for FFI_ArrowSchema {
type Error = ArrowError;

fn try_from(field: &Field) -> Result<Self> {
let flags = if field.is_nullable() {
let mut flags = if field.is_nullable() {
Flags::NULLABLE
} else {
Flags::empty()
};

if let Some(true) = field.dict_is_ordered() {
flags |= Flags::DICTIONARY_ORDERED;
}

FFI_ArrowSchema::try_from(field.data_type())?
.with_name(field.name())?
.with_flags(flags)
Expand Down Expand Up @@ -435,4 +439,20 @@ mod tests {

Ok(())
}

#[test]
fn test_dictionary_ordered() -> Result<()> {
let schema = Schema::new(vec![Field::new_dict(
"dict",
DataType::Dictionary(Box::new(DataType::Int32), Box::new(DataType::Utf8)),
false,
0,
true,
)]);

let arrow_schema = FFI_ArrowSchema::try_from(schema)?;
assert!(arrow_schema.child(0).dictionary_ordered());

Ok(())
}
}
4 changes: 4 additions & 0 deletions arrow/src/ffi.rs
Expand Up @@ -288,6 +288,10 @@ impl FFI_ArrowSchema {
pub fn map_keys_sorted(&self) -> bool {
self.flags & 0b00000100 != 0
}

pub fn dictionary_ordered(&self) -> bool {
self.flags & 0b00000001 != 0
}
}

impl Drop for FFI_ArrowSchema {
Expand Down

0 comments on commit a2f223c

Please sign in to comment.