Example #1
0
        internal virtual void Not(GremlinToSqlContext currentContext, GremlinToSqlContext notContext)
        {
            WBooleanExpression booleanExpr = SqlUtil.GetNotExistPredicate(notContext.ToSelectQueryBlock());

            currentContext.AddPredicate(booleanExpr);
        }
Example #2
0
        internal virtual void Or(GremlinToSqlContext currentContext, List <GremlinToSqlContext> orContexts)
        {
            List <WBooleanExpression> booleanExprList = orContexts.Select(context => context.ToSqlBoolean()).ToList();

            currentContext.AddPredicate(SqlUtil.ConcatBooleanExprWithOr(booleanExprList));
        }
 internal override WScalarExpression ToStepScalarExpr()
 {
     return(SqlUtil.GetColumnReferenceExpr(GetVariableName(), GremlinKeyword.Path));
 }
        public override WTableReference ToTableReference()
        {
            var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Barrier, new List <WScalarExpression>(), GetVariableName());

            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
 public override WTableReference ToTableReference()
 {
     return(SqlUtil.GetNamedTableReference(this));
 }
        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);
        }
        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));
        }
Example #8
0
 internal WWhereClause GetWhereClause()
 {
     return(this.Predicates == null ? null : SqlUtil.GetWhereClause(this.Predicates));
 }
 internal override WScalarExpression ToStepScalarExpr(HashSet <string> composedProperties = null)
 {
     return(SqlUtil.GetColumnReferenceExpr(GetVariableName(), GremlinKeyword.Path));
 }
Example #10
0
        internal List <WSelectElement> GetSelectElement(List <string> ProjectedProperties)
        {
            var selectElements = new List <WSelectElement>();

            if ((PivotVariable is GremlinUnionVariable && HomeVariable is GremlinSideEffectVariable) ||
                PivotVariable.GetVariableType() == GremlinVariableType.NULL)
            {
                selectElements.Add(SqlUtil.GetSelectScalarExpr(SqlUtil.GetStarColumnReferenceExpr()));
            }
            else if (ProjectedProperties != null && ProjectedProperties.Count != 0)
            {
                foreach (var projectProperty in ProjectedProperties)
                {
                    WSelectScalarExpression selectScalarExpr;
                    if (projectProperty == GremlinKeyword.TableDefaultColumnName)
                    {
                        GremlinVariableProperty defaultProjection = PivotVariable.DefaultProjection();
                        selectScalarExpr = SqlUtil.GetSelectScalarExpr(defaultProjection.ToScalarExpression(), GremlinKeyword.TableDefaultColumnName);
                        selectElements.Add(selectScalarExpr);
                    }
                    else if (ProjectVariablePropertiesList.All(p => p.Item2 != projectProperty))
                    {
                        if (PivotVariable.ProjectedProperties.Contains(projectProperty))
                        {
                            WScalarExpression columnExpr =
                                PivotVariable.GetVariableProperty(projectProperty).ToScalarExpression();
                            selectScalarExpr = SqlUtil.GetSelectScalarExpr(columnExpr, projectProperty);
                            selectElements.Add(selectScalarExpr);
                        }
                        else
                        {
                            selectScalarExpr = SqlUtil.GetSelectScalarExpr(SqlUtil.GetValueExpr(null), projectProperty);
                            selectElements.Add(selectScalarExpr);
                        }
                    }
                }
            }
            else
            {
                GremlinVariableProperty defaultProjection = PivotVariable.DefaultProjection();
                selectElements.Add(SqlUtil.GetSelectScalarExpr(defaultProjection.ToScalarExpression(), GremlinKeyword.TableDefaultColumnName));
            }

            if (IsPopulateGremlinPath)
            {
                selectElements.Add(SqlUtil.GetSelectScalarExpr(CurrentContextPath.DefaultProjection().ToScalarExpression(), GremlinKeyword.Path));
            }
            foreach (var item in ProjectVariablePropertiesList)
            {
                selectElements.Add(SqlUtil.GetSelectScalarExpr(item.Item1.ToScalarExpression(), item.Item2));
            }
            if (selectElements.Count == 0)
            {
                if (PivotVariable is GremlinTableVariable ||
                    (PivotVariable is GremlinUnionVariable && HomeVariable is GremlinSideEffectVariable))
                {
                    selectElements.Add(SqlUtil.GetSelectScalarExpr(SqlUtil.GetStarColumnReferenceExpr()));
                }
                else if (PivotVariable.GetVariableType() == GremlinVariableType.Table)
                {
                    throw new Exception("Can't process table type");
                }
                else
                {
                    GremlinVariableProperty defaultProjection = PivotVariable.DefaultProjection();
                    selectElements.Add(SqlUtil.GetSelectScalarExpr(defaultProjection.ToScalarExpression()));
                }
            }

            return(selectElements);
        }
Example #11
0
 public WScalarExpression ToScalarExpression()
 {
     return(SqlUtil.GetColumnReferenceExpr(GremlinVariable.GetVariableName(), VariableProperty));
 }
 public override WTableReference ToTableReference()
 {
     return(SqlUtil.GetDerivedTable(SubqueryContext.ToSelectQueryBlock(ProjectedProperties), GetVariableName()));
 }
Example #13
0
        internal override GremlinToSqlContext GetContext()
        {
            GremlinToSqlContext inputContext = GetInputContext();

            if (inputContext.PivotVariable == null)
            {
                throw new QueryCompilationException("The PivotVariable can't be null.");
            }

            RepeatTraversal.GetStartOp().InheritedVariableFromParent(inputContext);
            GremlinToSqlContext repeatContext = RepeatTraversal.GetEndOp().GetContext();

            foreach (var variable in repeatContext.TableReferences)
            {
                if (variable is GremlinFoldVariable ||
                    variable is GremlinCountVariable ||
                    variable is GremlinMinVariable ||
                    variable is GremlinMaxVariable ||
                    variable is GremlinSumVariable ||
                    variable is GremlinMeanVariable ||
                    variable is GremlinTreeVariable)
                {
                    throw new SyntaxErrorException($"The parent of a reducing barrier can not be repeat()-step: {variable.GetType()}");
                }
                var group = variable as GremlinGroupVariable;
                if (group != null && group.SideEffectKey == null)
                {
                    throw new SyntaxErrorException($"The parent of a reducing barrier can not be repeat()-step: {variable.GetType()}");
                }
            }
            foreach (var variable in repeatContext.FetchAllTableVars())
            {
                if (variable is GremlinRepeatVariable)
                {
                    throw new SyntaxErrorException("The repeat()-step can't include another nesting repeat()-step:");
                }
            }

            RepeatCondition repeatCondition = new RepeatCondition();

            repeatCondition.StartFromContext = StartFromContext;
            repeatCondition.IsEmitContext    = EmitContext;
            if (IsEmit)
            {
                GremlinToSqlContext emitContext = new GremlinToSqlContext();
                emitContext.AddPredicate(SqlUtil.GetTrueBooleanComparisonExpr());
                repeatCondition.EmitContext = emitContext;
            }
            if (TerminationPredicate != null)
            {
                throw new NotImplementedException();
            }
            if (TerminationTraversal != null)
            {
                if (StartFromContext)
                {
                    TerminationTraversal.GetStartOp().InheritedVariableFromParent(inputContext);
                }
                else
                {
                    TerminationTraversal.GetStartOp().InheritedVariableFromParent(repeatContext);
                }
                repeatCondition.TerminationContext = TerminationTraversal.GetEndOp().GetContext();
            }
            if (EmitPredicate != null)
            {
                throw new NotImplementedException();
            }
            if (EmitTraversal != null)
            {
                if (EmitContext)
                {
                    EmitTraversal.GetStartOp().InheritedVariableFromParent(inputContext);
                }
                else
                {
                    EmitTraversal.GetStartOp().InheritedVariableFromParent(repeatContext);
                }
                repeatCondition.EmitContext = EmitTraversal.GetEndOp().GetContext();
            }
            if (RepeatTimes != -1)
            {
                repeatCondition.RepeatTimes = RepeatTimes;
            }

            inputContext.PivotVariable.Repeat(inputContext, repeatContext, repeatCondition);

            return(inputContext);
        }