mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-09 02:04:22 +01:00
Converted the unconditional unwrap to a match which handles the case when the function is COUNT and args are None and replaces the args. Solves https://github.com/tursodatabase/limbo/issues/725
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use std::ops::Deref;
|
||||
|
||||
use super::emitter::emit_program;
|
||||
use super::expr::get_name;
|
||||
use super::plan::SelectQueryType;
|
||||
@@ -9,10 +11,10 @@ use crate::translate::planner::{
|
||||
parse_where, resolve_aggregates, OperatorIdCounter,
|
||||
};
|
||||
use crate::util::normalize_ident;
|
||||
use crate::SymbolTable;
|
||||
use crate::{schema::Schema, vdbe::builder::ProgramBuilder, Result};
|
||||
use sqlite3_parser::ast;
|
||||
use crate::{LimboError, SymbolTable};
|
||||
use sqlite3_parser::ast::ResultColumn;
|
||||
use sqlite3_parser::ast::{self, Expr};
|
||||
|
||||
pub fn translate_select(
|
||||
program: &mut ProgramBuilder,
|
||||
@@ -116,9 +118,25 @@ pub fn prepare_select_plan(
|
||||
args_count,
|
||||
) {
|
||||
Ok(Func::Agg(f)) => {
|
||||
let count_args = vec![ast::Expr::Literal(
|
||||
ast::Literal::Numeric("1".to_string()),
|
||||
)];
|
||||
let agg_args: Result<Vec<Expr>, LimboError> = match args {
|
||||
// if args is None and its COUNT
|
||||
None if name.0.to_uppercase() == "COUNT" => {
|
||||
Ok(count_args)
|
||||
}
|
||||
// if args is None and the function is not COUNT
|
||||
None => crate::bail_parse_error!(
|
||||
"Aggregate function {} requires arguments",
|
||||
name.0
|
||||
),
|
||||
Some(args) => Ok(args.clone()),
|
||||
};
|
||||
|
||||
let agg = Aggregate {
|
||||
func: f,
|
||||
args: args.as_ref().unwrap().clone(),
|
||||
args: agg_args?.clone(),
|
||||
original_expr: expr.clone(),
|
||||
};
|
||||
aggregate_expressions.push(agg.clone());
|
||||
|
||||
Reference in New Issue
Block a user