alamb commented on code in PR #8177:
URL: https://github.com/apache/arrow-rs/pull/8177#discussion_r2291474966


##########
parquet-variant-compute/src/cast_to_variant.rs:
##########
@@ -535,6 +535,44 @@ pub fn cast_to_variant(input: &dyn Array) -> 
Result<VariantArray, ArrowError> {
                 builder.append_variant(value);
             }
         }
+        DataType::Map(field, _) => match field.data_type() {
+            DataType::Struct(_) => {
+                let map_array = input.as_map();
+                let keys = cast_to_variant(map_array.keys())?;

Review Comment:
   We could also potentially cast this directly to a string aray here, somethin 
glike
   
   ```suggestion
                   let keys = cast(map_array.keys(), DataType::Utf8)?;
   ```
   
   And then you wouldn't have to worry about dealing with Variants
   
   I think what you have here, other than the unwrap, is looks good to me



##########
parquet-variant-compute/src/cast_to_variant.rs:
##########
@@ -1983,6 +2021,37 @@ mod tests {
         );
     }
 
+    #[test]
+    fn test_cast_map_to_variant_object() {

Review Comment:
   Can we please also add tests for:
   1. Keys are not strings
   2. There are nulls in the array?



##########
parquet-variant-compute/src/cast_to_variant.rs:
##########
@@ -535,6 +535,44 @@ pub fn cast_to_variant(input: &dyn Array) -> 
Result<VariantArray, ArrowError> {
                 builder.append_variant(value);
             }
         }
+        DataType::Map(field, _) => match field.data_type() {
+            DataType::Struct(_) => {
+                let map_array = input.as_map();
+                let keys = cast_to_variant(map_array.keys())?;
+                let values = cast_to_variant(map_array.values())?;
+                let offsets = map_array.offsets();
+
+                let mut start_offset = offsets[0];
+                for end_offset in offsets.iter().skip(1) {
+                    if start_offset >= *end_offset {
+                        builder.append_null();
+                        continue;
+                    }
+
+                    let length = (end_offset - start_offset) as usize;
+
+                    let mut variant_builder = VariantBuilder::new();
+                    let mut object_builder = variant_builder.new_object();
+
+                    for i in start_offset..*end_offset {
+                        let value = values.value(i as usize);
+                        object_builder.insert(keys.value(i as 
usize).as_string().unwrap(), value);

Review Comment:
   this will panic if the key can't be converted to a string -- can we make it 
an error instead?
   
   



-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to