From f59ec07ba16b38e66f3c86eaa2e244a306326b2b Mon Sep 17 00:00:00 2001 From: Runji Wang Date: Fri, 24 Nov 2023 16:20:49 +0800 Subject: [PATCH] introduce`AggCall::unchecked` Signed-off-by: Runji Wang --- src/expr/impl/src/aggregate/general.rs | 2 +- src/frontend/src/binder/select.rs | 14 +++----------- src/frontend/src/expr/agg_call.rs | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/expr/impl/src/aggregate/general.rs b/src/expr/impl/src/aggregate/general.rs index 7256bf24cd851..50dc1dc254f19 100644 --- a/src/expr/impl/src/aggregate/general.rs +++ b/src/expr/impl/src/aggregate/general.rs @@ -136,7 +136,7 @@ fn last_value(_: T, input: T) -> T { input } -#[aggregate("internal_last_seen_value(*) -> auto", state = "ref")] +#[aggregate("internal_last_seen_value(*) -> auto", state = "ref", internal)] fn internal_last_seen_value(state: T, input: T, retract: bool) -> T { if retract { state diff --git a/src/frontend/src/binder/select.rs b/src/frontend/src/binder/select.rs index ceb7d55312f46..bc2a8192f5799 100644 --- a/src/frontend/src/binder/select.rs +++ b/src/frontend/src/binder/select.rs @@ -40,10 +40,9 @@ use crate::catalog::system_catalog::rw_catalog::{ }; use crate::expr::{ AggCall, CorrelatedId, CorrelatedInputRef, Depth, Expr as _, ExprImpl, ExprType, FunctionCall, - InputRef, OrderBy, + InputRef, }; use crate::utils::group_by::GroupBy; -use crate::utils::Condition; #[derive(Debug, Clone)] pub struct BoundSelect { @@ -635,15 +634,8 @@ impl Binder { .into(); // There could be multiple indexes on a table so aggregate the sizes of all indexes - let select_items: Vec = vec![AggCall::new( - AggKind::Sum0, - vec![sum], - false, - OrderBy::any(), - Condition::true_cond(), - vec![], - )? - .into()]; + let select_items: Vec = + vec![AggCall::new_unchecked(AggKind::Sum, vec![sum], DataType::Int64)?.into()]; let indrelid_col = PG_INDEX_COLUMNS[1].1; let indrelid_ref = self.bind_column(&[indrelid_col.into()])?; diff --git a/src/frontend/src/expr/agg_call.rs b/src/frontend/src/expr/agg_call.rs index ff0a62ae0fc00..73031ff060177 100644 --- a/src/frontend/src/expr/agg_call.rs +++ b/src/frontend/src/expr/agg_call.rs @@ -72,6 +72,23 @@ impl AggCall { }) } + /// Constructs an `AggCall` without type inference. + pub fn new_unchecked( + agg_kind: AggKind, + args: Vec, + return_type: DataType, + ) -> Result { + Ok(AggCall { + agg_kind, + return_type, + args, + distinct: false, + order_by: OrderBy::any(), + filter: Condition::true_cond(), + direct_args: vec![], + }) + } + pub fn decompose( self, ) -> (