From 0ce444f01335e55b4e2c807729ceb6019145f9a0 Mon Sep 17 00:00:00 2001 From: Richard Chien Date: Mon, 10 Jul 2023 17:28:15 +0800 Subject: [PATCH] reject ApproxCountDistinct with `DISTINCT` Signed-off-by: Richard Chien --- src/frontend/src/binder/expr/function.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/frontend/src/binder/expr/function.rs b/src/frontend/src/binder/expr/function.rs index 263e2810c962..184d7153bd98 100644 --- a/src/frontend/src/binder/expr/function.rs +++ b/src/frontend/src/binder/expr/function.rs @@ -336,15 +336,6 @@ impl Binder { .map(|arg| self.bind_function_arg(arg.clone())) .flatten_ok() .try_collect()?; - - if f.distinct && args.is_empty() { - return Err(ErrorCode::InvalidInputSyntax(format!( - "DISTINCT is not allowed for aggregate function `{}` without args", - kind - )) - .into()); - } - let order_by = OrderBy::new( f.order_by .into_iter() @@ -353,6 +344,14 @@ impl Binder { ); if f.distinct { + if kind == AggKind::ApproxCountDistinct { + return Err(ErrorCode::InvalidInputSyntax(format!( + "DISTINCT is not allowed for approximate aggregation `{}`", + kind + )) + .into()); + } + if args.is_empty() { return Err(ErrorCode::InvalidInputSyntax(format!( "DISTINCT is not allowed for aggregate function `{}` without args",