public Dictionary <GremlinVariable, GremlinVariable> GetNewToOldSelectedVarMap(GremlinToSqlContext context) { Dictionary <GremlinVariable, GremlinVariable> newToOldSelectedVarMap = new Dictionary <GremlinVariable, GremlinVariable>(); if (context == null) { return(newToOldSelectedVarMap); } var allVariables = context.FetchAllVars().Distinct().ToList(); var allTableVariables = context.FetchAllTableVars(); for (var i = 1; i < allVariables.Count; i++) { if (!allTableVariables.Select(var => var.GetVariableName()).ToList().Contains(allVariables[i].GetVariableName())) { newToOldSelectedVarMap[allVariables[i]] = allVariables[i]; } } return(newToOldSelectedVarMap); }
internal override GremlinToSqlContext GetContext() { GremlinToSqlContext inputContext = GetInputContext(); if (inputContext.PivotVariable == null) { throw new TranslationException("The PivotVariable of has()-step can't be null."); } switch (Type) { //has(key) case GremlinHasType.HasProperty: inputContext.PivotVariable.Has(inputContext, PropertyKey); break; //hasNot(key) case GremlinHasType.HasNotProperty: inputContext.PivotVariable.HasNot(inputContext, PropertyKey); break; //has(key, value) | has(key, predicate) case GremlinHasType.HasPropertyValueOrPredicate: inputContext.PivotVariable.Has(inputContext, PropertyKey, ValueOrPredicate); break; //has(key, traversal) case GremlinHasType.HasPropertyTraversal: Traversal.GetStartOp().InheritedVariableFromParent(inputContext); if (Traversal.GetStartOp() is GremlinParentContextOp) { if (Traversal.GremlinTranslationOpList.Count > 1) { Traversal.InsertGremlinOperator(1, new GremlinValuesOp(PropertyKey)); } else { Traversal.AddGremlinOperator(new GremlinValuesOp(PropertyKey)); } } GremlinToSqlContext hasContext = Traversal.GetEndOp().GetContext(); inputContext.AllTableVariablesInWhereClause.AddRange(hasContext.FetchAllTableVars()); inputContext.AddPredicate(hasContext.ToSqlBoolean()); break; //has(label, key, value) | has(label, key, predicate) case GremlinHasType.HasLabelPropertyValue: inputContext.PivotVariable.Has(inputContext, GremlinKeyword.Label, Label); inputContext.PivotVariable.Has(inputContext, PropertyKey, ValueOrPredicate); break; //hasId(values) case GremlinHasType.HasId: case GremlinHasType.HasLabel: inputContext.PivotVariable.HasIdOrLabel(inputContext, Type, ValuesOrPredicates); break; //=================================================================== //hasKey(values) || hasValue(values) case GremlinHasType.HasKey: case GremlinHasType.HasValue: inputContext.PivotVariable.HasKeyOrValue(inputContext, Type, ValuesOrPredicates); break; } return(inputContext); }
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); }
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); }