Ejemplo n.º 1
0
        public override IASTNode VisitAggregationFunction(SqlServerCommandParser.AggregationFunctionContext context)
        {
            var aggregationType = context.aggregationFunctionName().GetText();

            return(AggregationType.IsAggregationType(aggregationType)
                ? CreateAggregationSegment(context, aggregationType)
                : new ExpressionProjectionSegment(context.Start.StartIndex, context.Stop.StopIndex, context.GetText()));
        }
Ejemplo n.º 2
0
        private string GetDistinctExpression(SqlServerCommandParser.AggregationFunctionContext context)
        {
            StringBuilder result = new StringBuilder();

            for (int i = 3; i < context.ChildCount - 1; i++)
            {
                result.Append(context.GetChild(i).GetText());
            }

            return(result.ToString());
        }
Ejemplo n.º 3
0
        private IASTNode CreateAggregationSegment(SqlServerCommandParser.AggregationFunctionContext context, string aggregationType)
        {
            var type = AggregationType.ValueOf(aggregationType.ToUpper());
            int innerExpressionStartIndex = ((ITerminalNode)context.GetChild(1)).Symbol.StartIndex;

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

            return(new AggregationDistinctProjectionSegment(context.Start.StartIndex, context.Stop.StopIndex, type, innerExpressionStartIndex, GetDistinctExpression(context)));
        }