From d4c03d426c86b4a27dbf40e4f4b3264c237118d8 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Mon, 7 Jul 2025 19:54:57 +0300 Subject: [PATCH] core/translate: Fix aggregate star error handling in prepare_one_select_plan() For example, if we attempt to do `max(*)`, let's return the error message from `resolve_function()` to be compatible with SQLite: ``` sqlite> CREATE TABLE test1(f1, f2); sqlite> SELECT max(*) FROM test1; Parse error: wrong number of arguments to function max() SELECT max(*) FROM test1; ^--- error here ``` Spotted by SQLite TCL tests. --- core/translate/select.rs | 60 +++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/core/translate/select.rs b/core/translate/select.rs index a6013a562..25f23d993 100644 --- a/core/translate/select.rs +++ b/core/translate/select.rs @@ -452,32 +452,46 @@ fn prepare_one_select_plan( name, filter_over: _, } => { - if let Ok(Func::Agg(f)) = Func::resolve_function( + match Func::resolve_function( normalize_ident(name.0.as_str()).as_str(), 0, ) { - let agg = Aggregate { - func: f, - args: vec![ast::Expr::Literal(ast::Literal::Numeric( - "1".to_string(), - ))], - original_expr: expr.clone(), - distinctness: Distinctness::NonDistinct, - }; - aggregate_expressions.push(agg.clone()); - plan.result_columns.push(ResultSetColumn { - alias: maybe_alias.as_ref().map(|alias| match alias { - ast::As::Elided(alias) => alias.0.clone(), - ast::As::As(alias) => alias.0.clone(), - }), - expr: expr.clone(), - contains_aggregates: true, - }); - } else { - crate::bail_parse_error!( - "Invalid aggregate function: {}", - name.0 - ); + Ok(Func::Agg(f)) => { + let agg = Aggregate { + func: f, + args: vec![ast::Expr::Literal(ast::Literal::Numeric( + "1".to_string(), + ))], + original_expr: expr.clone(), + distinctness: Distinctness::NonDistinct, + }; + aggregate_expressions.push(agg.clone()); + plan.result_columns.push(ResultSetColumn { + alias: maybe_alias.as_ref().map(|alias| match alias { + ast::As::Elided(alias) => alias.0.clone(), + ast::As::As(alias) => alias.0.clone(), + }), + expr: expr.clone(), + contains_aggregates: true, + }); + } + Ok(_) => { + crate::bail_parse_error!( + "Invalid aggregate function: {}", + name.0 + ); + } + Err(e) => match e { + crate::LimboError::ParseError(e) => { + crate::bail_parse_error!("{}", e); + } + _ => { + crate::bail_parse_error!( + "Invalid aggregate function: {}", + name.0 + ); + } + }, } } expr => {