Apache DataFusion SQL Query Engine
Fix panic in `PercentileContGroupsAccumulator::convert_to_state()` (#25755)
Mason6a792c671376
diff --git a/datafusion/functions-aggregate/src/percentile_cont.rs b/datafusion/functions-aggregate/src/percentile_cont.rsindex 3dbaf40efa..5b1f6bdc1f 100644--- a/datafusion/functions-aggregate/src/percentile_cont.rs+++ b/datafusion/functions-aggregate/src/percentile_cont.rs@@ -718,8 +718,8 @@ wherevalues: &[ArrayRef],opt_filter: Option<&BooleanArray>,) -> Result<Vec<ArrayRef>> {- assert_eq!(values.len(), 1, "one argument to merge_batch");-+ // As in `update_batch`, only the first element holds the values; the+ // percentile parameter and the ORDER BY columns follow itlet input_array = values[0].as_primitive::<T>();// Directly convert the input array to states, each row will bediff --git a/datafusion/sqllogictest/test_files/aggregate_skip_partial.slt b/datafusion/sqllogictest/test_files/aggregate_skip_partial.sltindex d659e4c836..356eb9582c 100644--- a/datafusion/sqllogictest/test_files/aggregate_skip_partial.slt+++ b/datafusion/sqllogictest/test_files/aggregate_skip_partial.slt@@ -877,6 +877,27 @@ SELECT g, var(v ORDER BY i) FROM agg_order_by_t GROUP BY g ORDER BY g;1 22 4+# Test percentile_cont without WITHIN GROUP+query IR+SELECT g, percentile_cont(v, 0.25) FROM agg_order_by_t GROUP BY g ORDER BY g;+----+1 1.5+2 6++# Test percentile_cont with WITHIN GROUP+query IR+SELECT g, percentile_cont(0.5) WITHIN GROUP (ORDER BY v) FROM agg_order_by_t GROUP BY g ORDER BY g;+----+1 2+2 7++# Test percentile_cont with WITHIN GROUP and descending order+query IR+SELECT g, percentile_cont(0.25) WITHIN GROUP (ORDER BY v DESC) FROM agg_order_by_t GROUP BY g ORDER BY g;+----+1 2.5+2 8+statement okDROP TABLE agg_order_by_t;