alamb commented on code in PR #7338:
URL: https://github.com/apache/arrow-datafusion/pull/7338#discussion_r1301993038


##########
datafusion/optimizer/src/analyzer/type_coercion.rs:
##########
@@ -543,6 +543,77 @@ fn coerce_arguments_for_signature(
         .collect::<Result<Vec<_>>>()
 }
 
+// TODO: Add this function to arrow-rs
+fn get_list_base_type(data_type: &DataType) -> Result<DataType> {
+    match data_type {
+        DataType::List(field) => match field.data_type() {
+            DataType::List(_) => get_list_base_type(field.data_type()),
+            base_type => Ok(base_type.clone()),
+        },
+
+        _ => Ok(data_type.clone()),
+    }
+}
+
+fn get_list_from_base_type(
+    data_type: &DataType,
+    base_type: &DataType,
+) -> Result<DataType> {
+    match data_type {
+        DataType::List(field) => match field.data_type() {
+            DataType::List(inner_field) => 
Ok(DataType::List(Arc::new(Field::new(
+                field.name(),
+                get_list_from_base_type(inner_field.data_type(), base_type)?,
+                field.is_nullable(),
+            )))),
+            _ => Ok(DataType::List(Arc::new(Field::new(
+                field.name(),
+                base_type.clone(),
+                field.is_nullable(),
+            )))),
+        },
+
+        _ => Ok(base_type.clone()),
+    }
+}
+
+fn coerce_nulls_for_array_append(

Review Comment:
   Perhaps you could create a function like
   
   ```rust
   /// Given elements of input_types, returns the single field DataType  
   /// such that a `DataType::List` with that field type can store each element 
after coercion
   //
   // For example, given an [Int32, Int64, and NULL] this function would return 
Int64
   // meaning that the elements could all be stored in a  
`DataType::List(Int64)` 
   // (after first being cast to Int64)`  
   fn coerce_array_args(input_types: Vec<DataType>) -> Result<DataType> {
   ...
   }
   ```
   
   I think this would generalize simply to lists of lists but I haven't thought 
about it myself



##########
datafusion/optimizer/src/analyzer/type_coercion.rs:
##########
@@ -543,6 +543,77 @@ fn coerce_arguments_for_signature(
         .collect::<Result<Vec<_>>>()
 }
 
+// TODO: Add this function to arrow-rs
+fn get_list_base_type(data_type: &DataType) -> Result<DataType> {
+    match data_type {
+        DataType::List(field) => match field.data_type() {
+            DataType::List(_) => get_list_base_type(field.data_type()),
+            base_type => Ok(base_type.clone()),
+        },
+
+        _ => Ok(data_type.clone()),
+    }
+}
+
+fn get_list_from_base_type(
+    data_type: &DataType,
+    base_type: &DataType,
+) -> Result<DataType> {
+    match data_type {
+        DataType::List(field) => match field.data_type() {
+            DataType::List(inner_field) => 
Ok(DataType::List(Arc::new(Field::new(
+                field.name(),
+                get_list_from_base_type(inner_field.data_type(), base_type)?,
+                field.is_nullable(),
+            )))),
+            _ => Ok(DataType::List(Arc::new(Field::new(
+                field.name(),
+                base_type.clone(),
+                field.is_nullable(),
+            )))),
+        },
+
+        _ => Ok(base_type.clone()),
+    }
+}
+
+fn coerce_nulls_for_array_append(

Review Comment:
   Perhaps you could create a function like
   
   ```rust
   /// Given elements of input_types, returns the single field DataType  
   /// such that a `DataType::List` with that field type can store each element 
after coercion
   //
   // For example, given an [Int32, Int64, and NULL] this function would return 
Int64
   // meaning that the elements could all be stored in a  
`DataType::List(Int64)` 
   // (after first being cast to Int64)`  
   fn coerce_array_args(input_types: Vec<DataType>) -> Result<DataType> {
   ...
   }
   ```
   
   I think this would generalize simply to lists of lists but I haven't thought 
about it deeply



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