public override IASTNode VisitAggregationFunction(MySqlCommandParser.AggregationFunctionContext ctx)
        {
            String aggregationType = ctx.aggregationFunctionName().GetText();

            return(AggregationType.IsAggregationType(aggregationType)
                    ? CreateAggregationSegment(ctx, aggregationType) : new ExpressionProjectionSegment(ctx.Start.StartIndex, ctx.Stop.StopIndex, ctx.GetText()));
        }
        private String getDistinctExpression(MySqlCommandParser.AggregationFunctionContext ctx)
        {
            StringBuilder result = new StringBuilder();

            for (int i = 3; i < ctx.ChildCount - 1; i++)
            {
                result.Append(ctx.GetChild(i).GetText());
            }
            return(result.ToString());
        }
        private IASTNode CreateAggregationSegment(MySqlCommandParser.AggregationFunctionContext ctx, String aggregationType)
        {
            AggregationTypeEnum type      = AggregationType.ValueOf(aggregationType.ToUpper());
            int innerExpressionStartIndex = ((ITerminalNode)ctx.GetChild(1)).Symbol.StartIndex;

            if (null == ctx.distinct())
            {
                return(new AggregationProjectionSegment(ctx.Start.StartIndex, ctx.Stop.StopIndex, type, innerExpressionStartIndex));
            }
            return(new AggregationDistinctProjectionSegment(ctx.Start.StartIndex, ctx.Stop.StopIndex, type, innerExpressionStartIndex, getDistinctExpression(ctx)));
        }