Пример #1
0
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            foreach (GremlinToSqlContext context in this.CoalesceContextList)
            {
                WSelectQueryBlock selectQueryBlock = context.ToSelectQueryBlock();
                Dictionary <string, WSelectElement> projectionMap = new Dictionary <string, WSelectElement>();
                WSelectElement value = selectQueryBlock.SelectElements[0];
                foreach (WSelectElement selectElement in selectQueryBlock.SelectElements)
                {
                    projectionMap[(selectElement as WSelectScalarExpression).ColumnName] = selectElement;
                }
                selectQueryBlock.SelectElements.Clear();

                selectQueryBlock.SelectElements.Add(SqlUtil.GetSelectScalarExpr((value as WSelectScalarExpression).SelectExpr, this.DefaultProperty()));
                foreach (string property in this.ProjectedProperties)
                {
                    selectQueryBlock.SelectElements.Add(
                        projectionMap.TryGetValue(property, out value)
                            ? value : SqlUtil.GetSelectScalarExpr(SqlUtil.GetValueExpr(null), property));
                }
                parameters.Add(SqlUtil.GetScalarSubquery(selectQueryBlock));
            }

            var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Coalesce, parameters, GetVariableName());

            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
        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));
        }
        internal override string ToString(string indent)
        {
            StringBuilder sb = new StringBuilder(128);

            WSelectElement sourceElement = SelectDeleteExpr.SelectElements[0];
            WSelectElement sinkElement   = SelectDeleteExpr.SelectElements[1];

            sb.AppendFormat("{0}DELETE EDGE {1}-{2}->{3}",
                            indent,
                            sourceElement.ToString(""),
                            EdgeColumn.ToString(""),
                            sinkElement.ToString(""));

            sb.Append("\r\n");
            sb.Append(SelectDeleteExpr.FromClause.ToString(indent));

            // For the DELETE EDGE statement, the first path in the parsed MATCH clause is
            // the one-hop path, i.e., the edge, to be deleted.
            if (SelectDeleteExpr.MatchClause.Paths.Count > 1)
            {
                sb.Append("\r\n");
                sb.AppendFormat("{0}MATCH {1}", indent, SelectDeleteExpr.MatchClause.Paths[1].ToString(""));

                for (int i = 2; i < SelectDeleteExpr.MatchClause.Paths.Count; i++)
                {
                    sb.Append("\r\n");
                    sb.AppendFormat("  {0}{1}", indent, SelectDeleteExpr.MatchClause.Paths[i].ToString(""));
                }
            }

            if (SelectDeleteExpr.WhereClause != null && SelectDeleteExpr.WhereClause.SearchCondition != null)
            {
                sb.Append("\r\n");
                sb.Append(SelectDeleteExpr.WhereClause.ToString(indent));
            }

            return(sb.ToString());
        }
Пример #4
0
 public virtual void Visit(WSelectElement node)
 {
     node.AcceptChildren(this);
 }
Пример #5
0
 public virtual void Visit(WSelectElement node)
 {
     node.AcceptChildren(this);
 }
Пример #6
0
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();
            WTableReference          tableReference;

            if (this.PredicateContext != null)
            {
                parameters.Add(SqlUtil.GetScalarSubquery(this.PredicateContext.ToSelectQueryBlock()));

                // Align
                List <WSelectQueryBlock> selectQueryBlocks = new List <WSelectQueryBlock>();
                selectQueryBlocks.Add(this.TrueChoiceContext.ToSelectQueryBlock());
                selectQueryBlocks.Add(this.FalseChocieContext.ToSelectQueryBlock());

                foreach (WSelectQueryBlock selectQueryBlock in selectQueryBlocks)
                {
                    Dictionary <string, WSelectElement> projectionMap = new Dictionary <string, WSelectElement>();
                    WSelectElement value = selectQueryBlock.SelectElements[0];
                    foreach (WSelectElement selectElement in selectQueryBlock.SelectElements)
                    {
                        projectionMap[(selectElement as WSelectScalarExpression).ColumnName] = selectElement;
                    }
                    selectQueryBlock.SelectElements.Clear();

                    selectQueryBlock.SelectElements.Add(SqlUtil.GetSelectScalarExpr((value as WSelectScalarExpression).SelectExpr, this.DefaultProperty()));
                    foreach (string property in this.ProjectedProperties)
                    {
                        selectQueryBlock.SelectElements.Add(
                            projectionMap.TryGetValue(property, out value)
                                ? value : SqlUtil.GetSelectScalarExpr(SqlUtil.GetValueExpr(null), property));
                    }
                    parameters.Add(SqlUtil.GetScalarSubquery(selectQueryBlock));
                }
                parameters.AddRange(selectQueryBlocks.Select(SqlUtil.GetScalarSubquery));

                tableReference = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Choose, parameters, GetVariableName());
            }
            else
            {
                parameters.Add(SqlUtil.GetScalarSubquery(this.ChoiceContext.ToSelectQueryBlock()));

                foreach (var option in this.Options)
                {
                    if (option.Key is GremlinKeyword.Pick && (GremlinKeyword.Pick)option.Key == GremlinKeyword.Pick.None)
                    {
                        parameters.Add(SqlUtil.GetValueExpr(null));
                    }
                    else
                    {
                        parameters.Add(SqlUtil.GetValueExpr(option.Key));
                    }

                    //Align
                    WSelectQueryBlock selectQueryBlock = option.Value.ToSelectQueryBlock();
                    Dictionary <string, WSelectElement> projectionMap = new Dictionary <string, WSelectElement>();
                    WSelectElement value = selectQueryBlock.SelectElements[0];
                    foreach (WSelectElement selectElement in selectQueryBlock.SelectElements)
                    {
                        projectionMap[(selectElement as WSelectScalarExpression).ColumnName] = selectElement;
                    }
                    selectQueryBlock.SelectElements.Clear();

                    selectQueryBlock.SelectElements.Add(SqlUtil.GetSelectScalarExpr((value as WSelectScalarExpression).SelectExpr, this.DefaultProperty()));
                    foreach (string property in this.ProjectedProperties)
                    {
                        selectQueryBlock.SelectElements.Add(
                            projectionMap.TryGetValue(property, out value)
                                ? value : SqlUtil.GetSelectScalarExpr(SqlUtil.GetValueExpr(null), property));
                    }
                    parameters.Add(SqlUtil.GetScalarSubquery(selectQueryBlock));
                }
                tableReference = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.ChooseWithOptions, parameters, GetVariableName());
            }
            return(SqlUtil.GetCrossApplyTableReference(tableReference));
        }