wjones127 commented on code in PR #3925:
URL: https://github.com/apache/arrow-rs/pull/3925#discussion_r1148279751


##########
arrow-array/src/array/map_array.rs:
##########
@@ -251,6 +251,69 @@ impl std::fmt::Debug for MapArray {
     }
 }
 
+impl TryFrom<&ListArray> for MapArray {
+    type Error = ArrowError;
+    fn try_from(value: &ListArray) -> Result<Self, Self::Error> {
+        let field = match value.data_type() {
+            DataType::List(field) => {
+                if let DataType::Struct(fields) = field.data_type() {
+                    if fields.len() != 2 {
+                        Err(ArrowError::InvalidArgumentError(
+                            "List item must be a struct type with two 
fields".to_string(),
+                        ))
+                    } else {
+                        Ok(field)
+                    }
+                } else {
+                    Err(ArrowError::InvalidArgumentError(
+                        "List item must be a struct type to convert to a list"
+                            .to_string(),
+                    ))
+                }
+            }
+            _ => unreachable!("This should be a list type."),
+        }?;
+        let old_data = value.to_data();
+        let array_data = unsafe {
+            ArrayData::new_unchecked(
+                DataType::Map(field.clone(), false),
+                old_data.len(),
+                Some(old_data.null_count()),
+                old_data.nulls().map(|nulls|nulls.buffer().clone()),
+                old_data.offset(),
+                old_data.buffers().to_vec(),
+                old_data.child_data().to_vec(),
+            )
+        };

Review Comment:
   Thanks, that's much better!



##########
arrow-array/src/array/map_array.rs:
##########
@@ -251,6 +251,69 @@ impl std::fmt::Debug for MapArray {
     }
 }
 
+impl TryFrom<&ListArray> for MapArray {

Review Comment:
   I removed this one.



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