swanandx commented on code in PR #3683:
URL: https://github.com/apache/iceberg-rust/pull/3683#discussion_r4703733350


##########
crates/iceberg/src/arrow/record_batch_transformer.rs:
##########
@@ -494,19 +524,49 @@ impl PromotePlan {
                     *sorted,
                 )?))
             }
+            PromotePlan::Unshred {
+                target_type,
+                name,
+                field_id,
+            } => {
+                let (storage_fields, columns, nulls) = array
+                    .as_struct_opt()
+                    .ok_or_else(|| promote_err(array, "struct"))?
+                    .clone()
+                    .into_parts();
+                // `unshred_variant` skips null rows, so mark the rows under a 
null parent as
+                // null. The output keeps the nulls of `array`, because Arrow 
rejects a null in
+                // a required child of a valid row.
+                let skip = arrow_buffer::NullBuffer::union(parent_nulls, 
nulls.as_ref());
+                let storage = StructArray::try_new(storage_fields, columns, 
skip)?;
+                let unshredded = VariantArray::try_new(&storage)
+                    .and_then(|variant| unshred_variant(&variant))
+                    .map_err(|e| {
+                        invalid_data!(
+                            "Variant column `{name}` (field id {field_id}) has 
invalid shredded data: {e}"
+                        )
+                    })?;
+                let (fields, columns, _) = cast(&ArrayRef::from(unshredded), 
target_type)?
+                    .as_struct()
+                    .clone()
+                    .into_parts();
+                Ok(Arc::new(StructArray::try_new(fields, columns, nulls)?))
+            }
         }
     }
 
     fn apply_struct(
         source: &StructArray,
         fields: &Fields,
         children: &[ChildPlan],
+        parent_nulls: Option<&arrow_buffer::NullBuffer>,
     ) -> Result<StructArray> {
+        let nulls = arrow_buffer::NullBuffer::union(parent_nulls, 
source.nulls());

Review Comment:
   done with an unshred_below flag, set at plan build.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to