vegarsti commented on code in PR #17891:
URL: https://github.com/apache/datafusion/pull/17891#discussion_r2415027061


##########
datafusion/functions-aggregate/src/array_agg.rs:
##########
@@ -687,13 +687,16 @@ impl Accumulator for OrderSensitiveArrayAggAccumulator {
 
         // Convert array to Scalars to sort them easily. Convert back to array 
at evaluation.
         let array_agg_res = 
ScalarValue::convert_array_to_scalar_vec(array_agg_values)?;
-        for v in array_agg_res.into_iter() {
-            partition_values.push(v.into());
+        for maybe_v in array_agg_res.into_iter() {
+            if let Some(v) = maybe_v {
+                partition_values.push(v.into());
+            } else {
+                partition_values.push(vec![].into());
+            }

Review Comment:
   So, the sqllogictests still pass if we do this -- zip the lists to filter 
the `None`-corresponding element from agg_orderings -- but I don't think it's 
particularly readable 😄  I don't know if this was what you were thinking of, 
though.
   
   ```
           // Convert array to Scalars to sort them easily. Convert back to 
array at evaluation.
           let array_agg_res = 
ScalarValue::convert_array_to_scalar_vec(array_agg_values)?;
           let orderings = 
ScalarValue::convert_array_to_scalar_vec(agg_orderings)?;
           if array_agg_res.len() != orderings.len() {
               return exec_err!(
                   "Expects values and ordering_values to have same size but 
got {} and {}",
                   array_agg_res.len(),
                   orderings.len()
               );
           }
           for (array_agg_res, partition_ordering_rows) in
               array_agg_res.into_iter().zip(orderings.into_iter())
           {
               if let Some(array_agg_res) = array_agg_res {
                   partition_values.push(array_agg_res.into());
               } else {
                   continue;
               }
   
               if let Some(partition_ordering_rows) = partition_ordering_rows {
                   // Extract value from struct to ordering_rows for each 
group/partition
                   let ordering_value = 
partition_ordering_rows.into_iter().map(|ordering_row| {
                   if let ScalarValue::Struct(s) = ordering_row {
                       let mut ordering_columns_per_row = vec![];
   
                       for column in s.columns() {
                           let sv = ScalarValue::try_from_array(column, 0)?;
                           ordering_columns_per_row.push(sv);
                       }
   
                       Ok(ordering_columns_per_row)
                   } else {
                       exec_err!(
                           "Expects to receive 
ScalarValue::Struct(Arc<StructArray>) but got:{:?}",
                           ordering_row.data_type()
                       )
                   }
               }).collect::<Result<VecDeque<_>>>()?;
                   partition_ordering_values.push(ordering_value);
               } else {
                   panic!("unreachable");
               }
           }
   ```



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to