From 54cf468c54d0069d74a54f4228a53ba0c29d52ee Mon Sep 17 00:00:00 2001 From: Fletcher555 Date: Thu, 25 Sep 2025 14:02:29 -0400 Subject: [PATCH 1/3] Small improvements to select with alias' still major issues with other function types and complex math --- src/interpreter/ast/helpers/common.rs | 36 ++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/interpreter/ast/helpers/common.rs b/src/interpreter/ast/helpers/common.rs index 266e6a7..f245849 100644 --- a/src/interpreter/ast/helpers/common.rs +++ b/src/interpreter/ast/helpers/common.rs @@ -1,6 +1,6 @@ use crate::interpreter::{ ast::{ - ExistenceCheck, LogicalOperator, MathOperator, Operator, OrderByDirection, + ExistenceCheck, FunctionName, FunctionSignature, LogicalOperator, MathOperator, Operator, OrderByDirection, SelectStatementColumn, SelectStatementTable, SelectableStack, SelectableStackElement, helpers::token::token_to_value, parser::Parser, }, @@ -116,6 +116,12 @@ pub fn get_selectables( current_name += token.value; } continue; + } else if token.token_type == TokenTypes::As { + parser.advance()?; + if parser.current_token()?.token_type == TokenTypes::Identifier { + current_alias = Some(parser.current_token()?.value.to_string()); + } + continue; } else if token.token_type == TokenTypes::LeftParen { operators.push(ExtendedSelectableStackElement::LeftParen); current_name += token.value; @@ -252,6 +258,34 @@ pub fn get_selectables( current_name = column.column_name.clone(); SelectableStackElement::Column(column) } + TokenTypes::Count => { + let mut function_name = token.value.to_string(); + let has_parentheses = if let Ok(peek_token) = parser.peek_token() { + peek_token.token_type == TokenTypes::LeftParen + } else { + false + }; + + if has_parentheses { + parser.advance()?; + function_name += parser.current_token()?.value; + + parser.advance()?; + while parser.current_token()?.token_type != TokenTypes::RightParen { + function_name += parser.current_token()?.value; + parser.advance()?; + } + + function_name += parser.current_token()?.value; + } + + current_name = function_name; + SelectableStackElement::Function(FunctionSignature { + name: FunctionName::CountFunction, + input_count: 0, + has_parentheses, + }) + } _ => return Err(parser.format_error()), // TODO: better error handling }; output.push(element); From 25d384010786dbcbdf5eebefc58256f17d0ae73a Mon Sep 17 00:00:00 2001 From: Fletcher555 Date: Thu, 25 Sep 2025 14:03:16 -0400 Subject: [PATCH 2/3] Add todo --- src/interpreter/ast/helpers/common.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interpreter/ast/helpers/common.rs b/src/interpreter/ast/helpers/common.rs index f245849..accb8db 100644 --- a/src/interpreter/ast/helpers/common.rs +++ b/src/interpreter/ast/helpers/common.rs @@ -258,7 +258,7 @@ pub fn get_selectables( current_name = column.column_name.clone(); SelectableStackElement::Column(column) } - TokenTypes::Count => { + TokenTypes::Count => { // TODO: GENERALIZE THIS FOR ALL FUNCTIONS let mut function_name = token.value.to_string(); let has_parentheses = if let Ok(peek_token) = parser.peek_token() { peek_token.token_type == TokenTypes::LeftParen From 04a2f1ff4bcf3e756c9e811098df3f845356cb35 Mon Sep 17 00:00:00 2001 From: Fletcher555 Date: Thu, 25 Sep 2025 14:04:12 -0400 Subject: [PATCH 3/3] Fix issue with test causing failure on CI --- src/interpreter/ast/helpers/common.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/interpreter/ast/helpers/common.rs b/src/interpreter/ast/helpers/common.rs index accb8db..9b875d2 100644 --- a/src/interpreter/ast/helpers/common.rs +++ b/src/interpreter/ast/helpers/common.rs @@ -1,8 +1,8 @@ use crate::interpreter::{ ast::{ - ExistenceCheck, FunctionName, FunctionSignature, LogicalOperator, MathOperator, Operator, OrderByDirection, - SelectStatementColumn, SelectStatementTable, SelectableStack, SelectableStackElement, - helpers::token::token_to_value, parser::Parser, + ExistenceCheck, FunctionName, FunctionSignature, LogicalOperator, MathOperator, Operator, + OrderByDirection, SelectStatementColumn, SelectStatementTable, SelectableStack, + SelectableStackElement, helpers::token::token_to_value, parser::Parser, }, tokenizer::token::TokenTypes, }; @@ -258,27 +258,28 @@ pub fn get_selectables( current_name = column.column_name.clone(); SelectableStackElement::Column(column) } - TokenTypes::Count => { // TODO: GENERALIZE THIS FOR ALL FUNCTIONS + TokenTypes::Count => { + // TODO: GENERALIZE THIS FOR ALL FUNCTIONS let mut function_name = token.value.to_string(); let has_parentheses = if let Ok(peek_token) = parser.peek_token() { peek_token.token_type == TokenTypes::LeftParen } else { false }; - + if has_parentheses { parser.advance()?; function_name += parser.current_token()?.value; - + parser.advance()?; while parser.current_token()?.token_type != TokenTypes::RightParen { function_name += parser.current_token()?.value; parser.advance()?; } - + function_name += parser.current_token()?.value; } - + current_name = function_name; SelectableStackElement::Function(FunctionSignature { name: FunctionName::CountFunction,