예제 #1
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;
        }
예제 #2
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);
        }
예제 #3
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);
        }