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


##########
datafusion/common/src/scalar.rs:
##########
@@ -2039,7 +2039,11 @@ impl ScalarValue {
         }
     }
 
-    /// Retrieve ScalarValue for each row in `array`
+    /// Retrieve `ScalarValue` for each row in `array`
+    ///

Review Comment:
   This seems left over
   
   ```suggestion
   ```



##########
datafusion/common/src/scalar.rs:
##########
@@ -2039,7 +2039,11 @@ impl ScalarValue {
         }
     }
 
-    /// Retrieve ScalarValue for each row in `array`
+    /// Retrieve `ScalarValue` for each row in `array`
+    ///
+    /// Convert `ListArray` to `Vec<Vec<ScalarValue>>`, first `Vec` is for 
rows, second `Vec` is for elements in the list

Review Comment:
   👍 It might also help to explain why we need two different signatures. It 
took me a while to grok things too
   
   ```suggestion
       /// Convert `ListArray` into a 2 dimensional to `Vec<Vec<ScalarValue>>`, 
first `Vec` is for rows, 
       /// second `Vec` is for elements in the list.
       ///
       /// See [`Self::convert_non_list_array_to_scalars`] for converting non 
Lists
       ///
       /// This method is an optimization to unwrap nested ListArrays to nested 
Rust structures without
       /// converting them twice
   ```



##########
datafusion/common/src/scalar.rs:
##########
@@ -2067,30 +2071,78 @@ impl ScalarValue {
     ///
     /// assert_eq!(scalar_vec, expected);
     /// ```
-    pub fn convert_array_to_scalar_vec(array: &dyn Array) -> 
Result<Vec<Vec<Self>>> {
-        let mut scalars = Vec::with_capacity(array.len());
+    pub fn convert_list_array_to_scalar_vec<O: OffsetSizeTrait>(

Review Comment:
   I think this would be easier to use if it didn't mix generic and non generic 
code
   
   Maybe something like
   
   ```suggestion
       pub fn convert_list_array_to_scalar_vec(
         array: &dyn Array,
       ) -> Result<Vec<Vec<Self>>> {    
           if let Some(arr) = array.as_list_opt::<i32> {
               Self::convert_list_array_to_scalar_vec_internal(arr)
           } else if let Some(arr) = array.as_list_opt::<64> {
               Self::convert_list_array_to_scalar_vec_internal(arr)
           } else {
               _internal_err!("Expected GenericListArray but found: {array:?}")
           }
       }
   ```
   
   And then internally pass in the cast Array  by changing
   
   ```
       fn convert_list_array_to_scalar_vec_internal<O: OffsetSizeTrait>(
           array: &dyn Array,
       ) -> Result<Vec<Vec<Self>>> {
   ```
   
   to
   
   ```
       fn convert_list_array_to_scalar_vec_internal<O: OffsetSizeTrait>(
           array: &GenericListArray<O>,
       ) -> Result<Vec<Vec<Self>>> {
   ```



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