Implement AVG, COUNT, MAX, MIN, SUM functions

This commit is contained in:
Pijus Kamandulis
2024-03-11 19:10:41 +02:00
parent b72bba86c8
commit 6ed74688ca
7 changed files with 1429 additions and 560 deletions

View File

@@ -327,6 +327,7 @@ FunctionCall <- StringFunctions
/ TypeCheckingFunctions
/ ArrayFunctions
/ InFunction
/ AggregateFunctions
StringFunctions <- StringEqualsExpression
/ ToStringExpression
@@ -356,6 +357,12 @@ TypeCheckingFunctions <- IsDefined
/ IsPrimitive
/ IsString
AggregateFunctions <- AvgAggregateExpression
/ CountAggregateExpression
/ MaxAggregateExpression
/ MinAggregateExpression
/ SumAggregateExpression
ArrayFunctions <- ArrayConcatExpression
/ ArrayLengthExpression
/ ArraySliceExpression
@@ -509,6 +516,26 @@ InFunction <- ex1:SelectProperty ws "IN"i ws "(" ws ex2:SelectItem others:(ws ",
return createFunctionCall(parsers.FunctionCallIn, append([]interface{}{ex1, ex2}, others.([]interface{})...))
}
AvgAggregateExpression <- "AVG"i "(" ws ex:SelectItem ws ")" {
return createFunctionCall(parsers.FunctionCallAggregateAvg, []interface{}{ex})
}
CountAggregateExpression <- "COUNT"i "(" ws ex:SelectItem ws ")" {
return createFunctionCall(parsers.FunctionCallAggregateCount, []interface{}{ex})
}
MaxAggregateExpression <- "MAX"i "(" ws ex:SelectItem ws ")" {
return createFunctionCall(parsers.FunctionCallAggregateMax, []interface{}{ex})
}
MinAggregateExpression <- "MIN"i "(" ws ex:SelectItem ws ")" {
return createFunctionCall(parsers.FunctionCallAggregateMin, []interface{}{ex})
}
SumAggregateExpression <- "SUM"i "(" ws ex:SelectItem ws ")" {
return createFunctionCall(parsers.FunctionCallAggregateSum, []interface{}{ex})
}
Integer <- [0-9]+ {
return strconv.Atoi(string(c.text))
}