Skip to content

Commit

Permalink
Allow calling aggregation function with upper or lower case
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed Jul 14, 2023
1 parent a409a54 commit 84ceca8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,20 +279,21 @@ fn parse_select_statement(
}

// Check if aggregation function name is valid
if !AGGREGATIONS.contains_key(&field_name.as_str()) {
let function_name = field_name.to_lowercase();
if !AGGREGATIONS.contains_key(function_name.as_str()) {
return Err(GQLError {
message: "Invalid GQL aggregation function name".to_owned(),
location: field_name_location,
});
}

// Type check aggregation function argument type
let prototype = AGGREGATIONS_PROTOS.get(&field_name.as_str()).unwrap();
let prototype = AGGREGATIONS_PROTOS.get(function_name.as_str()).unwrap();
let field_type = TABLES_FIELDS_TYPES.get(argument.literal.as_str()).unwrap();
if prototype.parameter != DataType::Any && field_type != &prototype.parameter {
let message = format!(
"Aggregation Function `{}` expect parameter type `{}` but got type `{}`",
field_name.to_string(),
function_name,
&prototype.parameter.literal(),
field_type.literal()
);
Expand Down Expand Up @@ -338,7 +339,7 @@ fn parse_select_statement(
aggregations.insert(
column_name.to_string(),
AggregateFunction {
function_name: field_name.to_string(),
function_name: function_name,
argument: argument.literal.to_string(),
},
);
Expand Down

0 comments on commit 84ceca8

Please sign in to comment.