smiklos commented on code in PR #7002:
URL: https://github.com/apache/arrow-datafusion/pull/7002#discussion_r1269895851


##########
datafusion/core/src/physical_plan/unnest.rs:
##########
@@ -263,43 +263,27 @@ fn unnest_batch<T>(
     schema: &SchemaRef,
     column: &Column,
     list_array: &T,
+    list_array_values: &Arc<dyn Array>,
 ) -> Result<RecordBatch>
 where
     T: ArrayAccessor<Item = ArrayRef>,
 {
-    // Create an array with the unnested values of the list array, given the 
list
-    // array:
-    //
-    //   [1], null, [2, 3, 4], null, [5, 6]
-    //
-    // the result array is:
-    //
-    //   1, null, 2, 3, 4, null, 5, 6
-    //
-    let unnested_array = unnest_array(list_array)?;
-
-    // Create an array with the lengths of each list value in the nested array.
-    // Given the nested array:
-    //
-    //   [1], null, [2, 3, 4], null, [5, 6]
-    //
-    // the result array is:
-    //
-    //   1, null, 3, null, 2
-    //
-    // Depending on the list type the result may be Int32Array or Int64Array.
     let list_lengths = list_lengths(list_array)?;
 
     // Create the indices for the take kernel and then use those indices to 
create
     // the unnested record batch.
     match list_lengths.data_type() {
         DataType::Int32 => {
             let list_lengths = as_primitive_array::<Int32Type>(&list_lengths)?;
+            let unnested_array =
+                unnest_array(list_array, list_array_values, list_lengths)?;

Review Comment:
   Can you clarify which take indices you mean? 
   The ones that were already on main were used to expand the rest of the 
columns (their values and not the one that is unnested). 
   
   So unnest_array is simply needed as we need to change that column 
(physically unnest it).
   The take indices for the rest of the columns could be calculated based on 
the values array, it was perhaps prettier to have this intermediate state 
initially. I can try and get rid of list_sizes all together.



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