public override void Visit(WBinaryQueryExpression node)
 {
     if (node.BinaryQueryExprType != BinaryQueryExpressionType.Union)
     {
         throw new NodeViewException("Only UNION ALL can be used in Select Statement.");
     }
     base.Visit(node);
 }
        public override WTableReference ToTableReference()
        {
            List <WSelectQueryBlock> selectQueryBlocks = new List <WSelectQueryBlock>();

            selectQueryBlocks.Add(new WSelectQueryBlock());
            selectQueryBlocks.Add(this.OptionalContext.ToSelectQueryBlock());

            Dictionary <string, WSelectElement> projectionMap = new Dictionary <string, WSelectElement>();
            WSelectElement value = selectQueryBlocks[1].SelectElements[0];

            foreach (WSelectElement selectElement in selectQueryBlocks[1].SelectElements)
            {
                projectionMap[(selectElement as WSelectScalarExpression).ColumnName] = selectElement;
            }
            selectQueryBlocks[1].SelectElements.Clear();

            selectQueryBlocks[0].SelectElements.Add(SqlUtil.GetSelectScalarExpr(this.InputVariable.DefaultProjection().ToScalarExpression(), this.DefaultProperty()));
            selectQueryBlocks[1].SelectElements.Add(SqlUtil.GetSelectScalarExpr((value as WSelectScalarExpression).SelectExpr, this.DefaultProperty()));
            foreach (string property in this.ProjectedProperties)
            {
                selectQueryBlocks[0].SelectElements.Add(
                    SqlUtil.GetSelectScalarExpr(
                        this.InputVariable.RealVariable.ProjectedProperties.Contains(property)
                            ? this.InputVariable.RealVariable.GetVariableProperty(property).ToScalarExpression()
                            : SqlUtil.GetValueExpr(null), property));

                selectQueryBlocks[1].SelectElements.Add(
                    projectionMap.TryGetValue(property, out value)
                        ? value : SqlUtil.GetSelectScalarExpr(SqlUtil.GetValueExpr(null), property));
            }


            WBinaryQueryExpression binaryQueryExpression = SqlUtil.GetBinaryQueryExpr(selectQueryBlocks[0], selectQueryBlocks[1]);

            List <WScalarExpression> parameters = new List <WScalarExpression>();

            parameters.Add(SqlUtil.GetScalarSubquery(binaryQueryExpression));
            var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Optional, parameters, GetVariableName());

            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
Exemple #3
0
        internal void Split(out WSelectQueryBlock contextSelect, out WSelectQueryBlock repeatSelectQuery)
        {
            WScalarSubquery repeatInput = Parameters[0] as WScalarSubquery;

            if (repeatInput == null)
            {
                throw new SyntaxErrorException("The input of a repeat table reference must be a scalar subquery.");
            }
            WBinaryQueryExpression binaryQuery = repeatInput.SubQueryExpr as WBinaryQueryExpression;

            if (binaryQuery == null || binaryQuery.BinaryQueryExprType != BinaryQueryExpressionType.Union || !binaryQuery.All)
            {
                throw new SyntaxErrorException("The input of a repeat table reference must be a UNION ALL binary query expression.");
            }

            contextSelect     = binaryQuery.FirstQueryExpr as WSelectQueryBlock;
            repeatSelectQuery = binaryQuery.SecondQueryExpr as WSelectQueryBlock;

            if (contextSelect == null || repeatSelectQuery == null)
            {
                throw new SyntaxErrorException("The input of a repeat table reference must be a UNION ALL binary query and the two sub-queries must be a select query block.");
            }
        }
Exemple #4
0
        private WSelectQueryExpression ParseSelectQueryStatement(QueryExpression queryExpr)
        {

            if (queryExpr == null)
            {
                return null;
            }

            switch (queryExpr.GetType().Name)
            {
                case "BinaryQueryExpression":
                    {
                        var bqe = queryExpr as BinaryQueryExpression;
                        var pQueryExpr = new WBinaryQueryExpression
                        {
                            All = bqe.All,
                            FirstQueryExpr = ParseSelectQueryStatement(bqe.FirstQueryExpression),
                            SecondQueryExpr = ParseSelectQueryStatement(bqe.SecondQueryExpression),
                            FirstTokenIndex = bqe.FirstTokenIndex,
                            LastTokenIndex = bqe.LastTokenIndex
                        };

                        //pQueryExpr.OrderByExpr = parseOrderbyExpr(bqe.OrderByClause);

                        return pQueryExpr;
                    }
                case "QueryParenthesisExpression":
                    {
                        var qpe = queryExpr as QueryParenthesisExpression;
                        var pQueryExpr = new WQueryParenthesisExpression
                        {
                            QueryExpr = ParseSelectQueryStatement(qpe.QueryExpression),
                            FirstTokenIndex = qpe.FirstTokenIndex,
                            LastTokenIndex = qpe.LastTokenIndex
                        };

                        //pQueryExpr.OrderByExpr = parseOrderbyExpr(qpe.OrderByClause);

                        return pQueryExpr;
                    }
                case "QuerySpecification":
                    {
                        var qs = queryExpr as QuerySpecification;
                        var pQueryExpr = new WSelectQueryBlock
                        {
                            FirstTokenIndex = qs.FirstTokenIndex,
                            LastTokenIndex = qs.LastTokenIndex,
                            SelectElements = new List<WSelectElement>(qs.SelectElements.Count),
                        };

                        //
                        // SELECT clause
                        // 
                        foreach (var wsel in qs.SelectElements.Select(ParseSelectElement).Where(wsel => wsel != null))
                        {
                            pQueryExpr.SelectElements.Add(wsel);
                        }

                        //
                        // Top row filter
                        // 
                        if (qs.TopRowFilter != null)
                        {
                            pQueryExpr.TopRowFilter = new WTopRowFilter
                            {
                                Percent = qs.TopRowFilter.Percent,
                                WithTies = qs.TopRowFilter.WithTies,
                                Expression = ParseScalarExpression(qs.TopRowFilter.Expression),
                                FirstTokenIndex = qs.TopRowFilter.FirstTokenIndex,
                                LastTokenIndex = qs.TopRowFilter.LastTokenIndex
                            };
                        }

                        pQueryExpr.UniqueRowFilter = qs.UniqueRowFilter;

                        //
                        // FROM clause
                        //
                        if (qs.FromClause != null && qs.FromClause.TableReferences != null)
                        {
                            pQueryExpr.FromClause.FirstTokenIndex = qs.FromClause.FirstTokenIndex;
                            pQueryExpr.FromClause.LastTokenIndex = qs.FromClause.LastTokenIndex;
                            pQueryExpr.FromClause.TableReferences = new List<WTableReference>(qs.FromClause.TableReferences.Count);
                            foreach (var pref in qs.FromClause.TableReferences.Select(ParseTableReference).Where(pref => pref != null))
                            {
                                pQueryExpr.FromClause.TableReferences.Add(pref);
                            }
                        }

                        //
                        // WHERE clause
                        //

                        if (qs.WhereClause != null && qs.WhereClause.SearchCondition != null)
                        {
                            pQueryExpr.WhereClause.FirstTokenIndex = qs.WhereClause.FirstTokenIndex;
                            pQueryExpr.WhereClause.LastTokenIndex = qs.WhereClause.LastTokenIndex;
                            pQueryExpr.WhereClause.SearchCondition = ParseBooleanExpression(qs.WhereClause.SearchCondition);
                        }

                        // GROUP-BY clause
                        if (qs.GroupByClause != null)
                        {
                            pQueryExpr.GroupByClause = ParseGroupbyClause(qs.GroupByClause);
                        }

                        // Having clause
                        if (qs.HavingClause != null)
                        {
                            pQueryExpr.HavingClause = new WHavingClause
                            {
                                SearchCondition = ParseBooleanExpression(qs.HavingClause.SearchCondition),
                                FirstTokenIndex = qs.HavingClause.FirstTokenIndex,
                                LastTokenIndex = qs.HavingClause.LastTokenIndex
                            };
                        }

                        //
                        // ORDER-BY clause
                        // 
                        if (qs.OrderByClause != null)
                        {
                            pQueryExpr.OrderByClause = ParseOrderbyClause(qs.OrderByClause);
                        }

                        return pQueryExpr;
                    }
                default:
                    return null;
            }
        }
 public virtual void Visit(WBinaryQueryExpression node)
 {
     node.AcceptChildren(this);
 }
        //public override void Visit(WQueryParenthesisExpression node)
        //{
        //    node.QueryExpr.Accept(this);
        //    _result = new WQueryParenthesisExpression
        //    {
        //        OrderByClause = node.OrderByClause,
        //        QueryExpr = _result
        //    };
        //}

        public override void Visit(WBinaryQueryExpression node)
        {
            throw new GraphViewException("Binary query expression is not allowed in INSERT EDGE statement.");
        }
 public virtual void Visit(WBinaryQueryExpression node)
 {
     node.AcceptChildren(this);
 }
Exemple #8
0
        //public override void Visit(WQueryParenthesisExpression node)
        //{
        //    node.QueryExpr.Accept(this);
        //    _result = new WQueryParenthesisExpression
        //    {
        //        OrderByClause = node.OrderByClause,
        //        QueryExpr = _result
        //    };
        //}

        public override void Visit(WBinaryQueryExpression node)
        {
            throw new GraphViewException("Binary query expression is not allowed in INSERT EDGE statement.");
        }
 public override void Visit(WBinaryQueryExpression node)
 {
     if (node.BinaryQueryExprType != BinaryQueryExpressionType.Union)
         throw new NodeViewException("Only UNION ALL can be used in Select Statement.");
     base.Visit(node);
 }