Exemplo n.º 1
0
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            parameters.Add(SqlUtil.GetScalarSubquery(GetSelectQueryBlock(this.FromVertexContext)));
            parameters.Add(SqlUtil.GetScalarSubquery(GetSelectQueryBlock(this.ToVertexContext)));

            if (this.ToVertexContext == null && this.FromVertexContext != null)
            {
                this.OtherVIndex = 0;
            }
            if (this.ToVertexContext != null && this.FromVertexContext == null)
            {
                this.OtherVIndex = 1;
            }
            if (this.ToVertexContext != null && this.FromVertexContext != null)
            {
                this.OtherVIndex = 1;
            }

            parameters.Add(SqlUtil.GetValueExpr(this.OtherVIndex));

            parameters.Add(SqlUtil.GetValueExpr(this.EdgeLabel));
            parameters.AddRange(this.EdgeProperties.Select(property => property.ToPropertyExpr()));
            var secondTableRef     = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.AddE, parameters, GetVariableName());
            var crossApplyTableRef = SqlUtil.GetCrossApplyTableReference(secondTableRef);

            crossApplyTableRef.FirstTableRef = this.IsFirstTableReference ? SqlUtil.GetDerivedTable(SqlUtil.GetSimpleSelectQueryBlock("1"), "_") : null;

            return(SqlUtil.GetCrossApplyTableReference(crossApplyTableRef));
        }
Exemplo n.º 2
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 <WScalarExpression> parameters = new List <WScalarExpression>();

            bool isFetchAll = false;

            if (this.PropertyKeys.Count == 0)
            {
                parameters.Add(this.InputVariable.DefaultProjection().ToScalarExpression());
                isFetchAll = true;
            }
            else
            {
                parameters.AddRange(this.PropertyKeys.Select(property => this.InputVariable.GetVariableProperty(property).ToScalarExpression()));
            }

            parameters.AddRange(this.ProjectedProperties.Select(SqlUtil.GetValueExpr));

            var tableRef =
                SqlUtil.GetFunctionTableReference(
                    isFetchAll ? GremlinKeyword.func.AllProperties : GremlinKeyword.func.Properties,
                    parameters, GetVariableName());

            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            bool isFetchAll = false;

            if (PropertyKeys.Count == 0)
            {
                parameters.Add(InputVariable.DefaultProjection().ToScalarExpression());
                isFetchAll = true;
            }
            else
            {
                foreach (var property in PropertyKeys)
                {
                    parameters.Add(InputVariable.GetVariableProperty(property).ToScalarExpression());
                }
            }

            foreach (var projectProperty in ProjectedProperties)
            {
                if (projectProperty == GremlinKeyword.TableDefaultColumnName)
                {
                    continue;
                }
                parameters.Add(SqlUtil.GetValueExpr(projectProperty));
            }

            var tableRef = SqlUtil.GetFunctionTableReference(isFetchAll ? GremlinKeyword.func.AllProperties : GremlinKeyword.func.Properties,
                                                             parameters, GetVariableName());

            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
Exemplo n.º 5
0
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();
            WTableReference          tableReference;

            if (PredicateContext != null)
            {
                parameters.Add(SqlUtil.GetScalarSubquery(PredicateContext.ToSelectQueryBlock()));
                parameters.Add(SqlUtil.GetScalarSubquery(TrueChoiceContext.ToSelectQueryBlock()));
                parameters.Add(SqlUtil.GetScalarSubquery(FalseChocieContext.ToSelectQueryBlock()));
                tableReference = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Choose, parameters, GetVariableName());
            }
            else
            {
                parameters.Add(SqlUtil.GetScalarSubquery(ChoiceContext.ToSelectQueryBlock()));
                foreach (var option in 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));
                    }

                    parameters.Add(SqlUtil.GetScalarSubquery(option.Value.ToSelectQueryBlock()));
                }
                tableReference = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.ChooseWithOptions, parameters, GetVariableName());
            }

            return(SqlUtil.GetCrossApplyTableReference(tableReference));
        }
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            if (DedupVariables.Count > 0)
            {
                foreach (var dedupVariable in DedupVariables)
                {
                    parameters.Add(dedupVariable.DefaultVariableProperty().ToScalarExpression());
                }
            }
            else if (DedupContext != null)
            {
                parameters.Add(SqlUtil.GetScalarSubquery(DedupContext.ToSelectQueryBlock()));
            }
            else
            {
                parameters.Add(InputVariable.DefaultVariableProperty().ToScalarExpression());
            }

            var tableRef = SqlUtil.GetFunctionTableReference(
                Scope == GremlinKeyword.Scope.global ? GremlinKeyword.func.DedupGlobal : GremlinKeyword.func.DedupLocal,
                parameters, GetVariableName());

            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
Exemplo n.º 7
0
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();
            bool isList = false;

            if (GremlinUtil.IsList(ConstantValue) || GremlinUtil.IsArray(ConstantValue))
            {
                isList = true;  //1 It's a list
                foreach (var value in (IEnumerable)ConstantValue)
                {
                    parameters.Add(SqlUtil.GetValueExpr(value));
                }
            }
            else if (GremlinUtil.IsNumber(ConstantValue) || ConstantValue is string || ConstantValue is bool)
            {
                parameters.Add(SqlUtil.GetValueExpr(ConstantValue));
            }
            else
            {
                throw new ArgumentException();
            }
            var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Constant, parameters, GetVariableName());

            ((WConstantReference)tableRef).IsList = isList;
            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            if (ConstantValue is List <object> )
            {
                foreach (var value in ConstantValue as List <object> )
                {
                    parameters.Add(SqlUtil.GetValueExpr(value));
                }
            }
            else if (ConstantValue is List <string> )
            {
                foreach (var value in ConstantValue as List <string> )
                {
                    parameters.Add(SqlUtil.GetValueExpr(value));
                }
            }
            else
            {
                parameters.Add(SqlUtil.GetValueExpr(ConstantValue));
            }
            var secondTableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Constant, parameters, this, GetVariableName());

            return(SqlUtil.GetCrossApplyTableReference(null, secondTableRef));
        }
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            if (SourceVariableProperty != null)
            {
                parameters.Add(SourceVariableProperty.ToScalarExpression());
            }
            if (SinkVariableProperty != null)
            {
                parameters.Add(SinkVariableProperty.ToScalarExpression());
            }
            foreach (var property in ProjectedProperties)
            {
                parameters.Add(SqlUtil.GetValueExpr(property));
            }

            WTableReference tableRef = null;

            if (SourceVariableProperty != null && SinkVariableProperty != null)
            {
                //BothV
                tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.BothV, parameters, GetVariableName());
            }
            else
            {
                tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.EtoV, parameters, GetVariableName());
            }

            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
Exemplo n.º 10
0
        public override WTableReference ToTableReference()
        {
            WSelectQueryBlock firstQueryExpr = new WSelectQueryBlock();

            foreach (var projectProperty in ProjectedProperties)
            {
                if (projectProperty == GremlinKeyword.TableDefaultColumnName)
                {
                    firstQueryExpr.SelectElements.Add(SqlUtil.GetSelectScalarExpr(InputVariable.GetDefaultProjection().ToScalarExpression(),
                                                                                  GremlinKeyword.TableDefaultColumnName));
                }
                else if (InputVariable.ProjectedProperties.Contains(projectProperty))
                {
                    firstQueryExpr.SelectElements.Add(
                        SqlUtil.GetSelectScalarExpr(
                            InputVariable.GetVariableProperty(projectProperty).ToScalarExpression(), projectProperty));
                }
                else
                {
                    firstQueryExpr.SelectElements.Add(
                        SqlUtil.GetSelectScalarExpr(SqlUtil.GetValueExpr(null), projectProperty));
                }
            }

            WSelectQueryBlock secondQueryExpr   = OptionalContext.ToSelectQueryBlock();
            bool HasAggregateFunctionAsChildren = false;

            foreach (var variable in OptionalContext.TableReferences)
            {
                if (variable is GremlinFoldVariable ||
                    variable is GremlinCountVariable ||
                    variable is GremlinMinVariable ||
                    variable is GremlinMaxVariable ||
                    variable is GremlinSumVariable ||
                    variable is GremlinMeanVariable ||
                    variable is GremlinTreeVariable)
                {
                    HasAggregateFunctionAsChildren = true;
                }
                var group = variable as GremlinGroupVariable;
                if (group != null && group.SideEffectKey == null)
                {
                    HasAggregateFunctionAsChildren = true;
                }
            }

            var WBinaryQueryExpression = SqlUtil.GetBinaryQueryExpr(firstQueryExpr, secondQueryExpr);

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

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

            ((WOptionalTableReference)tableRef).HasAggregateFunctionAsChildren = HasAggregateFunctionAsChildren;

            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
Exemplo n.º 11
0
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            parameters.Add(SqlUtil.GetScalarSubquery(MapContext.ToSelectQueryBlock(ProjectedProperties)));
            var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Map, parameters, GetVariableName());

            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
Exemplo n.º 12
0
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            parameters.Add(SqlUtil.GetValueExpr(this.Probability));
            var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Coin, parameters, GetVariableName());

            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
Exemplo n.º 13
0
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            parameters.AddRange(this.ProjectedProperties.Select(SqlUtil.GetValueExpr));
            WTableReference tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.V, parameters, this.GetVariableName());

            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
Exemplo n.º 14
0
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            parameters.Add(ProjectVariable.ToScalarExpression());
            var secondTableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Value, parameters, this, GetVariableName());

            return(SqlUtil.GetCrossApplyTableReference(null, secondTableRef));
        }
Exemplo n.º 15
0
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            parameters.Add(InputVariable.GetDefaultProjection().ToScalarExpression());
            var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.SumLocal, parameters, GetVariableName());

            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            parameters.Add(SqlUtil.GetScalarSubquery(SideEffectContext.ToSelectQueryBlock()));
            var secondTableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.SideEffect, parameters, this, GetVariableName());

            return(SqlUtil.GetCrossApplyTableReference(null, secondTableRef));
        }
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            parameters.Add(InputVariable.GetDefaultProjection().ToScalarExpression());
            parameters.Add(SqlUtil.GetValueExpr(Column == GremlinKeyword.Column.Keys ? "Keys" : "Values"));
            var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.SelectColumn, parameters, GetVariableName());

            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            parameters.Add(SqlUtil.GetValueExpr(SideEffectKey));
            parameters.Add(PathVariable.DefaultProjection().ToScalarExpression());
            var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Tree, parameters, GetVariableName());

            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            parameters.Add(this.InputVariable.DefaultProjection().ToScalarExpression());
            parameters.AddRange(this.PropertyKeys.Select(SqlUtil.GetValueExpr));
            var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.PropertyMap, parameters, GetVariableName());

            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
Exemplo n.º 20
0
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            parameters.Add(this.UpdateVariable.DefaultProjection().ToScalarExpression());
            parameters.AddRange(this.PropertyList.Select(vertexProperty => vertexProperty.ToPropertyExpr()));
            var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.UpdateProperties, parameters, GetVariableName());

            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
Exemplo n.º 21
0
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            parameters.Add(SqlUtil.GetColumnReferenceExpr(GremlinKeyword.Compose1TableDefaultName, GremlinKeyword.TableDefaultColumnName));
            parameters.AddRange(this.ProjectedProperties.Select(SqlUtil.GetValueExpr));

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

            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
Exemplo n.º 22
0
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>
            {
                SqlUtil.GetScalarSubquery(this.DedupContext.ToSelectQueryBlock())
            };

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

            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
Exemplo n.º 23
0
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters       = new List <WScalarExpression>();
            WSelectQueryBlock        selectQueryBlock = ProjectContext.ToSelectQueryBlock(true);

            parameters.Add(SqlUtil.GetScalarSubquery(selectQueryBlock));
            parameters.Add(SqlUtil.GetValueExpr(SideEffectKey));
            var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Store, parameters, GetVariableName());

            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            foreach (var context in CoalesceContextList)
            {
                parameters.Add(SqlUtil.GetScalarSubquery(context.ToSelectQueryBlock(ProjectedProperties)));
            }
            var secondTableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Coalesce, parameters, this, GetVariableName());

            return(SqlUtil.GetCrossApplyTableReference(null, secondTableRef));
        }
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            parameters.Add(SqlUtil.GetValueExpr(SideEffectKey));
            parameters.Add(SqlUtil.GetScalarSubquery(GroupByContext.ToSelectQueryBlock()));
            parameters.Add(SqlUtil.GetScalarSubquery(ProjectByContext.ToSelectQueryBlock()));
            var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Group, parameters, GetVariableName());

            ((WGroupTableReference)tableRef).IsProjectingACollection = IsProjectingACollection;
            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
Exemplo n.º 26
0
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            parameters.Add(SqlUtil.GetValueExpr(this.VertexLabel));
            parameters.AddRange(this.VertexProperties.Select(property => property.ToPropertyExpr()));
            var secondTableRef     = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.AddV, parameters, GetVariableName());
            var crossApplyTableRef = SqlUtil.GetCrossApplyTableReference(secondTableRef);

            crossApplyTableRef.FirstTableRef = this.IsFirstTableReference ? SqlUtil.GetDerivedTable(SqlUtil.GetSimpleSelectQueryBlock("1"), "_") : null;
            return(crossApplyTableRef);
        }
Exemplo n.º 27
0
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters  = new List <WScalarExpression>();
            List <WSelectQueryBlock> queryBlocks = new List <WSelectQueryBlock>();

            //Must toSelectQueryBlock before toCompose1 of variableList in order to populate needed columns
            foreach (var byContext in ByContexts)
            {
                queryBlocks.Add(byContext.ToSelectQueryBlock(true));
            }

            parameters.Add(InputVariable.GetDefaultProjection().ToScalarExpression());
            parameters.Add(PathVariable.GetDefaultProjection().ToScalarExpression());
            switch (Pop)
            {
            case GremlinKeyword.Pop.All:
                parameters.Add(SqlUtil.GetValueExpr("All"));
                break;

            case GremlinKeyword.Pop.First:
                parameters.Add(SqlUtil.GetValueExpr("First"));
                break;

            case GremlinKeyword.Pop.Last:
                parameters.Add(SqlUtil.GetValueExpr("Last"));
                break;
            }

            foreach (var selectKey in SelectKeys)
            {
                parameters.Add(SqlUtil.GetValueExpr(selectKey));
            }

            foreach (var block in queryBlocks)
            {
                parameters.Add(SqlUtil.GetScalarSubquery(block));
            }

            if (SelectKeys.Count == 1)
            {
                foreach (var projectProperty in ProjectedProperties)
                {
                    parameters.Add(SqlUtil.GetValueExpr(projectProperty));
                }
            }

            var tableRef = SqlUtil.GetFunctionTableReference(
                SelectKeys.Count == 1 ? GremlinKeyword.func.SelectOne: GremlinKeyword.func.Select,
                parameters, GetVariableName());

            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            parameters.Add(InputVariable.DefaultProjection().ToScalarExpression());
            foreach (var propertyKey in PropertyKeys)
            {
                parameters.Add(SqlUtil.GetValueExpr(propertyKey));
            }
            var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.PropertyMap, parameters, GetVariableName());

            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            parameters.Add(SqlUtil.GetColumnReferenceExpr("C", GremlinKeyword.TableDefaultColumnName));
            foreach (var projectProperty in ProjectedProperties)
            {
                parameters.Add(SqlUtil.GetValueExpr(projectProperty));
            }
            var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Decompose1, parameters, GetVariableName());

            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
Exemplo n.º 30
0
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            for (var i = 0; i < ProjectKeys.Count; i++)
            {
                parameters.Add(SqlUtil.GetScalarSubquery(ProjectContextList[i % ProjectContextList.Count].ToSelectQueryBlock()));
                parameters.Add(SqlUtil.GetValueExpr(ProjectKeys[i]));
            }
            var secondTableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Project, parameters, this, GetVariableName());

            return(SqlUtil.GetCrossApplyTableReference(null, secondTableRef));
        }