resolve aggregates from orderby as well

This commit is contained in:
jussisaurio
2024-11-24 21:20:55 +02:00
parent 885b6ecd76
commit 56b15193d0
2 changed files with 20 additions and 1 deletions

View File

@@ -20,6 +20,9 @@ impl OperatorIdCounter {
}
fn resolve_aggregates(expr: &ast::Expr, aggs: &mut Vec<Aggregate>) {
if aggs.iter().any(|a| a.original_expr == *expr) {
return;
}
match expr {
ast::Expr::FunctionCall { name, args, .. } => {
let args_count = if let Some(args) = &args {
@@ -433,6 +436,9 @@ pub fn prepare_select_plan<'a>(schema: &Schema, select: ast::Select) -> Result<P
};
bind_column_references(&mut expr, &plan.referenced_tables)?;
if let Some(aggs) = &mut plan.aggregates {
resolve_aggregates(&expr, aggs);
}
key.push((
expr,

View File

@@ -115,4 +115,17 @@ Dennis|Ward|1
Whitney|Walker|1
Robert|Villanueva|1
Cynthia|Thomas|1
Brandon|Tate|1}
Brandon|Tate|1}
do_execsql_test order-by-case-insensitive-aggregate {
select u.first_name, sum(u.age) from users u group by u.first_name order by SUM(u.aGe) desc limit 10;
} {Michael|11204
David|8758
Robert|8109
Jennifer|7700
John|7299
Christopher|6397
James|5921
Joseph|5711
Brian|5059
William|5047}