private IASTNode CreateProjection(SqlServerCommandParser.ProjectionContext context, AliasSegment alias)
        {
            IASTNode projection = Visit(context.expr());

            if (projection is AggregationProjectionSegment aggregationProjectionSegment)
            {
                aggregationProjectionSegment.SetAlias(alias);
                return(projection);
            }
            if (projection is ExpressionProjectionSegment expressionProjectionSegment)
            {
                expressionProjectionSegment.SetAlias(alias);
                return(projection);
            }
            if (projection is CommonExpressionSegment commonExpressionSegment)
            {
                ExpressionProjectionSegment commonResult = new ExpressionProjectionSegment(commonExpressionSegment.GetStartIndex(), commonExpressionSegment.GetStopIndex(), commonExpressionSegment.GetText());
                commonResult.SetAlias(alias);
                return(commonResult);
            }
            // FIXME :For DISTINCT()
            if (projection is ColumnSegment columnSegment)
            {
                ExpressionProjectionSegment columnResult = new ExpressionProjectionSegment(context.Start.StartIndex, context.Stop.StopIndex, context.GetText());
                columnResult.SetAlias(alias);
                return(columnResult);
            }
            if (projection is SubQueryExpressionSegment subQueryExpressionSegment)
            {
                SubQueryProjectionSegment subQueryResult = new SubQueryProjectionSegment(subQueryExpressionSegment.SubQuery);
                subQueryResult.SetAlias(alias);
                return(subQueryResult);
            }
            LiteralExpressionSegment    column = (LiteralExpressionSegment)projection;
            ExpressionProjectionSegment result = null == alias ? new ExpressionProjectionSegment(column.GetStartIndex(), column.GetStopIndex(), column.GetLiterals()?.ToString())
                : new ExpressionProjectionSegment(column.GetStartIndex(), context.alias().Stop.StopIndex, column.GetLiterals()?.ToString());

            result.SetAlias(alias);
            return(result);
        }
示例#2
0
        private IASTNode CreateProjection(MySqlCommandParser.ProjectionContext ctx, AliasSegment alias)
        {
            IASTNode projection = Visit(ctx.expr());

            if (projection is AggregationProjectionSegment aggregationProjectionSegment)
            {
                aggregationProjectionSegment.SetAlias(alias);
                return(projection);
            }
            if (projection is ExpressionProjectionSegment expressionProjection)
            {
                expressionProjection.SetAlias(alias);
                return(projection);
            }
            if (projection is CommonExpressionSegment commonExpressionSegment)
            {
                ExpressionProjectionSegment r = new ExpressionProjectionSegment(commonExpressionSegment.GetStartIndex(), commonExpressionSegment.GetStopIndex(), commonExpressionSegment.GetText());
                r.SetAlias(alias);
                return(r);
            }
            // FIXME :For DISTINCT()
            if (projection is ColumnSegment)
            {
                ExpressionProjectionSegment r = new ExpressionProjectionSegment(ctx.Start.StartIndex, ctx.Stop.StopIndex, ctx.GetText());
                r.SetAlias(alias);
                return(r);
            }
            if (projection is SubQueryExpressionSegment subQueryExpressionSegment)
            {
                SubQueryProjectionSegment r = new SubQueryProjectionSegment(subQueryExpressionSegment.SubQuery);
                r.SetAlias(alias);
                return(r);
            }
            LiteralExpressionSegment    column = (LiteralExpressionSegment)projection;
            ExpressionProjectionSegment result = null == alias ? new ExpressionProjectionSegment(column.GetStartIndex(), column.GetStopIndex(), $"{column.GetLiterals()}")
                    : new ExpressionProjectionSegment(column.GetStartIndex(), ctx.alias().Stop.StopIndex, $"{column.GetLiterals()}");

            result.SetAlias(alias);
            return(result);
        }