mbutrovich opened a new issue, #11603:
URL: https://github.com/apache/arrow-rs/issues/11603

   ### Describe the bug
   
   `FFI_ArrowSchema::try_from(&Field)` loses 
[`ARROW_FLAG_MAP_KEYS_SORTED`](https://github.com/apache/arrow/blob/6b4c5248127881c506d4e21e6c95a5c4ced5d0d4/docs/source/format/CDataInterface.rst?plain=1#L395-L396)
 for a map type. A `Map(_, true)` exported as a `Field` imports as `Map(_, 
false)`. Exporting the bare `DataType` keeps the flag, but children are 
exported as fields, so a sorted map inside a struct, list or union always loses 
it, and so does a top-level schema field.
   
   ### To Reproduce
   
   ```rust
   use std::sync::Arc;
   use arrow_schema::ffi::FFI_ArrowSchema;
   use arrow_schema::{DataType, Field, Fields};
   
   fn main() {
       let entries = Field::new("entries", 
DataType::Struct(Fields::from(vec![Field::new("key", DataType::Utf8, false), 
Field::new("value", DataType::Int32, true)])), false);
       let map = DataType::Map(Arc::new(entries), true);
       let from_type = FFI_ArrowSchema::try_from(&map).unwrap();
       let from_field = FFI_ArrowSchema::try_from(&Field::new("m", map, 
true)).unwrap();
       println!("from DataType: {}", DataType::try_from(&from_type).unwrap());
       println!("from Field:    {}", 
Field::try_from(&from_field).unwrap().data_type());
       // from DataType: Map(..., sorted), from Field: Map(..., unsorted)
   }
   ```
   
   ### Expected behavior
   
   Both conversions give `Map(..., sorted)`.
   
   ### Additional context
   
   `TryFrom<&DataType>` sets `Flags::MAP_KEYS_SORTED` for a sorted map 
([ffi.rs](https://github.com/apache/arrow-rs/blob/72887ed91c80002bb7ec755ce1e964bab07bebea/arrow-schema/src/ffi.rs#L783-L788)).
 `TryFrom<&Field>` then calls `with_flags` with only `NULLABLE` and 
`DICTIONARY_ORDERED` 
([ffi.rs](https://github.com/apache/arrow-rs/blob/72887ed91c80002bb7ec755ce1e964bab07bebea/arrow-schema/src/ffi.rs#L881-L894)),
 and `with_flags` replaces the flags rather than adding to them 
([ffi.rs](https://github.com/apache/arrow-rs/blob/72887ed91c80002bb7ec755ce1e964bab07bebea/arrow-schema/src/ffi.rs#L201-L203)).
 Combining with the flags already set would keep it.
   
   Found with property-based tests that build arrays in every physical layout 
the Arrow format allows.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to