Пример #1
0
        internal virtual void Repeat(GremlinToSqlContext currentContext, GremlinToSqlContext repeatContext,
                                     RepeatCondition repeatCondition)
        {
            GremlinVariableType variableType = repeatContext.PivotVariable.GetVariableType() == GetVariableType()
                ? GetVariableType()
                : GremlinVariableType.Table;

            GremlinRepeatVariable repeatVariable = new GremlinRepeatVariable(this, repeatContext, repeatCondition, variableType);

            currentContext.VariableList.Add(repeatVariable);
            currentContext.TableReferences.Add(repeatVariable);
            currentContext.SetPivotVariable(repeatVariable);

            //TODO: refactor
            List <GremlinVariable> allTableVars = repeatVariable.FetchAllTableVars();

            foreach (var variable in allTableVars)
            {
                var pathVariable = variable as GremlinGlobalPathVariable;
                if (pathVariable != null)
                {
                    repeatVariable.PopulateLocalPath();
                    foreach (var property in pathVariable.ProjectedProperties)
                    {
                        repeatContext.ContextLocalPath.Populate(property);
                    }
                    pathVariable.IsInRepeatContext = true;
                    pathVariable.PathList.Insert(pathVariable.PathList.FindLastIndex(p => p == repeatContext.StepList.First()), null);
                }
            }
        }
Пример #2
0
        public GremlinRepeatVariable(
            GremlinVariable inputVariable,
            GremlinToSqlContext repeatContext,
            RepeatCondition repeatCondition,
            GremlinVariableType variableType) : base(variableType)
        {
            this.InputVariable   = new GremlinContextVariable(inputVariable);
            this.RepeatContext   = repeatContext;
            this.RepeatCondition = repeatCondition;
            this.Count           = 0;
            GremlinRepeatContextVariable repeatContextVariable = this.RepeatContext.VariableList.First() as GremlinRepeatContextVariable;
            GremlinUntilContextVariable  untilContextVariable  = null;

            if (this.RepeatCondition.TerminationContext?.VariableList.Count > 0)
            {
                untilContextVariable = this.RepeatCondition.TerminationContext.VariableList.First() as GremlinUntilContextVariable;
            }
            GremlinEmitContextVariable emitContextVariable = null;

            if (this.RepeatCondition.EmitContext?.VariableList.Count > 0)
            {
                emitContextVariable = this.RepeatCondition.EmitContext?.VariableList?.First() as GremlinEmitContextVariable;
            }
            if (repeatContextVariable?.LabelPropertyList.Count > 0 ||
                untilContextVariable?.LabelPropertyList.Count > 0 || emitContextVariable?.LabelPropertyList.Count > 0)
            {
                this.PopulateLocalPath();
                repeatContextVariable?.SetContextLocalPath(this.RepeatContext.ContextLocalPath);
                untilContextVariable?.SetContextLocalPath(this.RepeatContext.ContextLocalPath);
                emitContextVariable?.SetContextLocalPath(this.RepeatContext.ContextLocalPath);
            }
        }
Пример #3
0
        internal virtual void Repeat(GremlinToSqlContext currentContext, GremlinToSqlContext repeatContext,
                                     RepeatCondition repeatCondition)
        {
            GremlinTableVariable newVariable = GremlinRepeatVariable.Create(this, repeatContext, repeatCondition);

            currentContext.VariableList.Add(newVariable);
            currentContext.TableReferences.Add(newVariable);
            currentContext.SetPivotVariable(newVariable);
        }
Пример #4
0
 public GremlinRepeatVariable(GremlinVariable inputVariable,
                              GremlinToSqlContext repeatContext,
                              RepeatCondition repeatCondition,
                              GremlinVariableType variableType)
     : base(variableType)
 {
     RepeatContext   = repeatContext;
     InputVariable   = inputVariable;
     RepeatCondition = repeatCondition;
 }
Пример #5
0
        internal virtual void Repeat(GremlinToSqlContext currentContext, GremlinToSqlContext repeatContext,
                                     RepeatCondition repeatCondition)
        {
            GremlinVariableType variableType = repeatContext.PivotVariable.GetVariableType() == GetVariableType()
                ? GetVariableType()
                : GremlinVariableType.Table;
            GremlinRepeatVariable newVariable = new GremlinRepeatVariable(this, repeatContext, repeatCondition, variableType);

            currentContext.VariableList.Add(newVariable);
            currentContext.TableReferences.Add(newVariable);
            currentContext.SetPivotVariable(newVariable);
        }
 public GremlinRepeatVariable(GremlinVariable inputVariable,
                              GremlinToSqlContext repeatContext,
                              RepeatCondition repeatCondition,
                              GremlinVariableType variableType)
     : base(variableType)
 {
     RepeatContext = repeatContext;
     RepeatContext.HomeVariable = this;
     InputVariable        = inputVariable;
     RepeatCondition      = repeatCondition;
     SelectedVariableList = new List <Tuple <string, GremlinRepeatSelectedVariable> >();
 }
Пример #7
0
        internal override GremlinToSqlContext GetContext()
        {
            GremlinToSqlContext inputContext = GetInputContext();

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

            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)
            {
                TerminationTraversal.GetStartOp().InheritedVariableFromParent(repeatContext);
                repeatCondition.TerminationContext = TerminationTraversal.GetEndOp().GetContext();
            }
            if (EmitPredicate != null)
            {
                throw new NotImplementedException();
            }
            if (EmitTraversal != null)
            {
                EmitTraversal.GetStartOp().InheritedVariableFromParent(repeatContext);
                repeatCondition.EmitContext = EmitTraversal.GetEndOp().GetContext();
            }
            if (RepeatTimes != -1)
            {
                repeatCondition.RepeatTimes = RepeatTimes;
            }

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

            return inputContext;
        }
Пример #8
0
        public static GremlinRepeatVariable Create(GremlinVariable inputVariable, GremlinToSqlContext repeatContext,
                                                   RepeatCondition repeatCondition)
        {
            if (repeatContext.PivotVariable.GetVariableType() == inputVariable.GetVariableType())
            {
                switch (inputVariable.GetVariableType())
                {
                case GremlinVariableType.Vertex:
                    return(new GremlinRepeatVertexVariable(inputVariable, repeatContext, repeatCondition));

                case GremlinVariableType.Edge:
                    return(new GremlinRepeatEdgeVariable(inputVariable, repeatContext, repeatCondition));

                case GremlinVariableType.Scalar:
                    return(new GremlinRepeatScalarVariable(inputVariable, repeatContext, repeatCondition));

                case GremlinVariableType.Property:
                    return(new GremlinRepeatPropertyVariable(inputVariable, repeatContext, repeatCondition));
                }
            }
            return(new GremlinRepeatTableVariable(inputVariable, repeatContext, repeatCondition));
        }
Пример #9
0
 public GremlinRepeatTableVariable(GremlinVariable inputVariable,
                                   GremlinToSqlContext repeatContext,
                                   RepeatCondition repeatCondition)
     : base(inputVariable, repeatContext, repeatCondition, GremlinVariableType.Table)
 {
 }
Пример #10
0
 public GremlinRepeatPropertyVariable(GremlinVariable inputVariable,
                                      GremlinToSqlContext repeatContext,
                                      RepeatCondition repeatCondition)
     : base(inputVariable, repeatContext, repeatCondition, GremlinVariableType.Property)
 {
 }
Пример #11
0
        internal override GremlinToSqlContext GetContext()
        {
            if (this.IsFake)
            {
                throw new TranslationException("The fake repeat operator can not get context");
            }

            GremlinToSqlContext inputContext = GetInputContext();

            if (inputContext.PivotVariable == null)
            {
                throw new TranslationException("The PivotVariable of repeat()-step can't be null.");
            }

            // Convert GremlinParentContextOp to GremlinRepeatParentContextOp
            // Because It is different for "__" in Repeat-traversal and in other operator-traversal such as FlatMap.
            var oldStartOp = RepeatTraversal.GetStartOp() as GremlinParentContextOp;

            Debug.Assert(oldStartOp != null);
            RepeatTraversal.ReplaceGremlinOperator(0, new GremlinRepeatParentContextOp(oldStartOp));

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

            foreach (var variable in repeatContext.TableReferencesInFromClause)
            {
                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)
            {
                // Convert GremlinParentContextOp to GremlinUntilParentContextOp
                // Because It is different for "__" in Until-traversal and in other operator-traversal such as FlatMap.
                var old = TerminationTraversal.GetStartOp() as GremlinParentContextOp;
                Debug.Assert(old != null);
                TerminationTraversal.ReplaceGremlinOperator(0, new GremlinUntilParentContextOp(old));

                this.TerminationTraversal.GetStartOp().InheritedVariableFromParent(inputContext);
                repeatCondition.TerminationContext = this.TerminationTraversal.GetEndOp().GetContext();
            }
            if (EmitPredicate != null)
            {
                throw new NotImplementedException();
            }
            if (EmitTraversal != null)
            {
                // Convert GremlinParentContextOp to GremlinEmitParentContextOp
                // Because It is different for "__" in Emit-traversal and in other operator-traversal such as FlatMap.
                var old = EmitTraversal.GetStartOp() as GremlinParentContextOp;
                Debug.Assert(old != null);
                EmitTraversal.ReplaceGremlinOperator(0, new GremlinEmitParentContextOp(old));

                this.EmitTraversal.GetStartOp().InheritedVariableFromParent(inputContext);
                repeatCondition.EmitContext = this.EmitTraversal.GetEndOp().GetContext();
            }
            if (RepeatTimes != -1)
            {
                repeatCondition.RepeatTimes = RepeatTimes;
            }

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

            return(inputContext);
        }
Пример #12
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);
        }