private void HandleSum(FunctionCall functionCall) { //Mark query as aggregate, all selects must be either aggregate or in group by var parameters = functionCall.Parameters; if (parameters.Count != 1) { throw new NotSupportedException("Sum can only take a single parameter"); } _inAggregateFunction = true; foreach (var parameter in parameters) { parameter.Accept(this); } _inAggregateFunction = false; var argumentAccessExpression = PopStack(); var callMethodExpression = AggregationUtils.CallSum(argumentAccessExpression, this._previousStage); AddExpressionToStack(callMethodExpression); var lastName = PopNameStack(); AddNameToStack($"sum({lastName})"); }
private void HandleCount(FunctionCall functionCall) { var parameters = functionCall.Parameters; if (functionCall.Wildcard) { AddExpressionToStack(AggregationUtils.CallCount(_previousStage)); AddNameToStack($"count(*)"); } else { throw new SqlErrorException("Count only works with '*' right now."); } }
public override void VisitFunctionCall(FunctionCall functionCall) { //throw new Exception("FIX FUNCTION CALL WILDCARD PARAMETER"); var parameterListBuilder = ImmutableList.CreateBuilder <Expression>(); foreach (var p in functionCall.Parameters) { p.Accept(this); var parameterExpression = PopStack(); parameterListBuilder.Add(parameterExpression); } Parameters = parameterListBuilder.ToImmutable(); var functionName = functionCall.FunctionName.ToLower(); switch (functionName) { case "count": FunctionName = functionName; OutType = typeof(long); AddNameToStack($"count(*)"); break; case "sum": FunctionName = functionName; var lastName = PopNameStack(); if (Parameters.Count != 1) { throw new SqlErrorException($"Sum can only be called with a single parameter"); } var parameter = Parameters[0]; OutType = AggregationUtils.GetSumOutputType(parameter.Type); AddNameToStack($"sum({lastName})"); break; default: throw new NotSupportedException(functionCall.FunctionName); } }