diff --git a/src/expr/core/src/aggregate/def.rs b/src/expr/core/src/aggregate/def.rs index 1fb985585cdfe..d35077698da67 100644 --- a/src/expr/core/src/aggregate/def.rs +++ b/src/expr/core/src/aggregate/def.rs @@ -313,7 +313,7 @@ pub mod agg_kinds { | PbAggKind::StddevSamp | PbAggKind::VarPop | PbAggKind::VarSamp - | PbAggKind::Grouping, + | PbAggKind::Grouping // ApproxPercentile always uses custom agg executors, // rather than an aggregation operator | PbAggKind::ApproxPercentile @@ -446,13 +446,14 @@ pub mod agg_kinds { macro_rules! ordered_set { () => { AggKind::Builtin( - PbAggKind::PercentileCont | PbAggKind::PercentileDisc | PbAggKind::Mode | PbAggKind::ApproxPercentile + PbAggKind::PercentileCont + | PbAggKind::PercentileDisc + | PbAggKind::Mode + | PbAggKind::ApproxPercentile, ) }; } pub use ordered_set; - - use crate::aggregate::{AggKind, PbAggKind}; } impl AggKind { diff --git a/src/frontend/src/binder/expr/function.rs b/src/frontend/src/binder/expr/function.rs index 10905bc85c016..b9610819756b4 100644 --- a/src/frontend/src/binder/expr/function.rs +++ b/src/frontend/src/binder/expr/function.rs @@ -515,7 +515,11 @@ impl Binder { } } (AggKind::Builtin(PbAggKind::Mode), [], [_arg]) => {} - (AggKind::Builtin(PbAggKind::ApproxPercentile), [percentile, relative_error], [_percentile_col]) => { + ( + AggKind::Builtin(PbAggKind::ApproxPercentile), + [percentile, relative_error], + [_percentile_col], + ) => { Self::decimal_to_float64(percentile, &kind)?; Self::decimal_to_float64(relative_error, &kind)?; } @@ -579,7 +583,7 @@ impl Binder { if matches!( kind, AggKind::Builtin(PbAggKind::ApproxCountDistinct) - | AggKind::Builtin(PbAggKind::ApproxPercentile) + | AggKind::Builtin(PbAggKind::ApproxPercentile) ) { return Err(ErrorCode::InvalidInputSyntax(format!( "DISTINCT is not allowed for approximate aggregation `{}`", diff --git a/src/frontend/src/expr/agg_call.rs b/src/frontend/src/expr/agg_call.rs index c058112daee50..452d37652d341 100644 --- a/src/frontend/src/expr/agg_call.rs +++ b/src/frontend/src/expr/agg_call.rs @@ -41,7 +41,6 @@ impl std::fmt::Debug for AggCall { .field("distinct", &self.distinct) .field("order_by", &self.order_by) .field("direct_args", &self.direct_args) - .field("user_defined", &self.user_defined.is_some()) .finish() } else { let mut builder = f.debug_tuple(&format!("{}", self.agg_kind)); diff --git a/src/frontend/src/optimizer/plan_node/generic/agg.rs b/src/frontend/src/optimizer/plan_node/generic/agg.rs index 419b6058f7c66..c0f41b8d82c70 100644 --- a/src/frontend/src/optimizer/plan_node/generic/agg.rs +++ b/src/frontend/src/optimizer/plan_node/generic/agg.rs @@ -107,7 +107,8 @@ impl Agg { let agg_kind_ok = !matches!(call.agg_kind, agg_kinds::simply_cannot_two_phase!()); let order_ok = matches!( call.agg_kind, - agg_kinds::result_unaffected_by_order_by!() | AggKind::ApproxPercentile + agg_kinds::result_unaffected_by_order_by!() + | AggKind::Builtin(PbAggKind::ApproxPercentile) ) || call.order_by.is_empty(); let distinct_ok = matches!(call.agg_kind, agg_kinds::result_unaffected_by_distinct!()) @@ -135,7 +136,7 @@ impl Agg { self.agg_calls.iter().all(|c| { matches!(c.agg_kind, agg_kinds::single_value_state!()) || (matches!(c.agg_kind, agg_kinds::single_value_state_iff_in_append_only!() if stream_input_append_only)) - || (matches!(c.agg_kind, AggKind::ApproxPercentile)) + || (matches!(c.agg_kind, AggKind::Builtin(PbAggKind::ApproxPercentile))) }) } diff --git a/src/frontend/src/optimizer/plan_node/logical_agg.rs b/src/frontend/src/optimizer/plan_node/logical_agg.rs index 07292e57e6b5e..67ada8c704b34 100644 --- a/src/frontend/src/optimizer/plan_node/logical_agg.rs +++ b/src/frontend/src/optimizer/plan_node/logical_agg.rs @@ -297,7 +297,7 @@ impl LogicalAgg { let mut approx_percentile_col_mapping = Vec::with_capacity(estimated_len); let mut non_approx_percentile_col_mapping = Vec::with_capacity(estimated_len); for (output_idx, agg_call) in self.agg_calls().iter().enumerate() { - if agg_call.agg_kind == AggKind::ApproxPercentile { + if agg_call.agg_kind == AggKind::Builtin(PbAggKind::ApproxPercentile) { approx_percentile_agg_calls.push(agg_call.clone()); approx_percentile_col_mapping.push(Some(output_idx)); } else { @@ -643,7 +643,7 @@ impl LogicalAggBuilder { _ => unreachable!(), } } - AggKind::ApproxPercentile => { + AggKind::Builtin(PbAggKind::ApproxPercentile) => { if agg_call.order_by.sort_exprs[0].order_type == OrderType::descending() { // Rewrite DESC into 1.0-percentile for approx_percentile. let prev_percentile = agg_call.direct_args[0].clone(); diff --git a/src/frontend/src/optimizer/rule/distinct_agg_rule.rs b/src/frontend/src/optimizer/rule/distinct_agg_rule.rs index 9d46343356172..52aad1336a7bb 100644 --- a/src/frontend/src/optimizer/rule/distinct_agg_rule.rs +++ b/src/frontend/src/optimizer/rule/distinct_agg_rule.rs @@ -59,7 +59,8 @@ impl Rule for DistinctAggRule { let agg_kind_ok = !matches!(c.agg_kind, agg_kinds::simply_cannot_two_phase!()); let order_ok = matches!( c.agg_kind, - agg_kinds::result_unaffected_by_order_by!() | AggKind::ApproxPercentile + agg_kinds::result_unaffected_by_order_by!() + | AggKind::Builtin(PbAggKind::ApproxPercentile) ) || c.order_by.is_empty(); agg_kind_ok && order_ok }) {