Skip to content

Apache DataFusion SQL Query Engine

Mark ARRAY_AGG(DISTINCT ...) not implemented (#1534)

James Katzb05feda77d04
diff --git a/datafusion/src/physical_plan/aggregates.rs b/datafusion/src/physical_plan/aggregates.rs
index 07b0ff8b33..036c69e9a4 100644
--- a/datafusion/src/physical_plan/aggregates.rs
+++ b/datafusion/src/physical_plan/aggregates.rs
@@ -207,11 +207,16 @@ pub fn create_aggregate_expr(
coerced_exprs_types[0].clone(),
))
}
- (AggregateFunction::ArrayAgg, _) => Arc::new(expressions::ArrayAgg::new(
+ (AggregateFunction::ArrayAgg, false) => Arc::new(expressions::ArrayAgg::new(
coerced_phy_exprs[0].clone(),
name,
coerced_exprs_types[0].clone(),
)),
+ (AggregateFunction::ArrayAgg, true) => {
+ return Err(DataFusionError::NotImplemented(
+ "ARRAY_AGG(DISTINCT) aggregations are not available".to_string(),
+ ));
+ }
(AggregateFunction::Min, _) => Arc::new(expressions::Min::new(
coerced_phy_exprs[0].clone(),
name,
@@ -332,7 +337,9 @@ pub fn signature(fun: &AggregateFunction) -> Signature {
#[cfg(test)]
mod tests {
use super::*;
+ use crate::error::DataFusionError::NotImplemented;
use crate::error::Result;
+ use crate::physical_plan::distinct_expressions::DistinctCount;
use crate::physical_plan::expressions::{
ApproxDistinct, ArrayAgg, Avg, Count, Max, Min, Stddev, Sum, Variance,
};
@@ -401,6 +408,51 @@ mod tests {
}
_ => {}
};
+
+ let result_distinct = create_aggregate_expr(
+ &fun,
+ true,
+ &input_phy_exprs[0..1],
+ &input_schema,
+ "c1",
+ );
+ match fun {
+ AggregateFunction::Count => {
+ let result_agg_phy_exprs_distinct = result_distinct?;
+ assert!(result_agg_phy_exprs_distinct
+ .as_any()
+ .is::<DistinctCount>());
+ assert_eq!("c1", result_agg_phy_exprs_distinct.name());
+ assert_eq!(
+ Field::new("c1", DataType::UInt64, true),
+ result_agg_phy_exprs_distinct.field().unwrap()
+ );
+ }
+ AggregateFunction::ApproxDistinct => {
+ let result_agg_phy_exprs_distinct = result_distinct?;
+ assert!(result_agg_phy_exprs_distinct
+ .as_any()
+ .is::<ApproxDistinct>());
+ assert_eq!("c1", result_agg_phy_exprs_distinct.name());
+ assert_eq!(
+ Field::new("c1", DataType::UInt64, false),
+ result_agg_phy_exprs_distinct.field().unwrap()
+ );
+ }
+ AggregateFunction::ArrayAgg => match result_distinct {
+ Err(NotImplemented(s)) => {
+ assert_eq!(
+ s,
+ "ARRAY_AGG(DISTINCT) aggregations are not available"
+ .to_string()
+ );
+ }
+ _ => {
+ unreachable!()
+ }
+ },
+ _ => {}
+ };
}
}
Ok(())