sainimal1ba-hue commented on PR #12086:
URL: https://github.com/apache/arrow-rs/pull/12086#issuecomment-7249697232

   > Nice improvement for untyped `VariantType` object fields and preserving 
`Field` metadata in `ShreddedSchemaBuilder`.
   > 
   > There is a gap when an untyped `VariantType` field is used as a list 
element (either via `ShreddedSchemaBuilder::default().with_path("items[*]", 
Arc::new(variant_field))` or directly in 
`DataType::List(Arc::new(variant_field))` / `LargeList` / `ListView` / 
`LargeListView`):
   > 
   > 1. `ShreddingField` and `VariantSchemaNode::to_shredding_field` already 
preserve the `VariantType` extension metadata on the generated `"item"` 
`FieldRef` inside `DataType::List(...)`.
   > 2. However, `shred_variant` routes list schemas through 
`VariantToListArrowRowBuilder::try_new` in 
`parquet-variant-compute/src/variant_to_arrow.rs` (when `shredded == true`), 
which passes only `element_data_type` to 
`make_variant_to_shredded_variant_arrow_row_builder` and ignores 
`field.has_valid_extension_type::<VariantType>()`.
   > 3. Because the storage `DataType` of `VariantType` is `Struct([metadata: 
BinaryView, value: BinaryView])` (or with `typed_value` if from a shredded 
`VariantArray`), `make_variant_to_shredded_variant_arrow_row_builder` treats 
every list element as a typed shredded object schema expecting keys 
`"metadata"` and `"value"`:
   >    
   >    * The list element's `ShreddedVariantFieldArray` gets a spurious 
`typed_value: Struct { metadata: ..., value: ... }` column instead of staying 
unshredded (`typed_value` absent / `value` only).
   >    * `Variant::Object` elements (e.g., `[{"a": 1}]` or `[{"value": 123}]`) 
produce a non-null `typed_value` struct and route `"metadata"` / `"value"` 
object keys into those nested shredded subfields instead of keeping the element 
unshredded in `elem.value`.
   > 4. Additionally, in `VariantToListArrowRowBuilder::finish`, 
`self.field.as_ref().clone().with_data_type(element_array.data_type().clone())` 
preserves `ARROW:extension:name = "arrow.parquet.variant"` on the shredded 
element `Field`, even though `element_array` is a `ShreddedVariantFieldArray` 
(`Struct { value, ... }` without `metadata`) rather than a `Variant` struct.
   > 
   > Handling `field.has_valid_extension_type::<VariantType>()` in 
`VariantToListArrowRowBuilder` / `ListElementBuilder` when `shredded == true` 
(using `NullValue::ArrayElement` so SQL NULL elements write `Variant::Null` 
into `value` with a valid bit in `ShreddedVariantFieldArray`, and clearing 
extension metadata from the output shredded element `Field`) would make list 
elements consistent with object fields.
   
   That gap is real, the PR only handles untyped variant object fields and list 
elements go through the typed shredding path whatever the element field says. 
Working on the VariantToListArrowRowBuilder / ListElementBuilder side now: 
check has_valid_extension_type::<VariantType>() on the element field when 
shredded == true, keep untyped elements unshredded, write SQL NULL elements as 
Variant::Null into value via NullValue::ArrayElement, and clear the extension 
metadata from the shredded element field in finish, so lists get the same 
treatment as object fields. Will push it with a list-element case next to the 
object field tests.


-- 
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