internal virtual void Is(GremlinToSqlContext currentContext, object value) { WScalarExpression firstExpr = DefaultVariableProperty().ToScalarExpression(); WScalarExpression secondExpr = SqlUtil.GetValueExpr(value); currentContext.AddPredicate(SqlUtil.GetEqualBooleanComparisonExpr(firstExpr, secondExpr)); }
internal virtual void Is(GremlinToSqlContext currentContext, Predicate predicate) { WScalarExpression firstExpr = GetDefaultProjection().ToScalarExpression(); WScalarExpression secondExpr = SqlUtil.GetValueExpr(predicate.Value); currentContext.AddPredicate(SqlUtil.GetBooleanComparisonExpr(firstExpr, secondExpr, predicate)); }
internal override GremlinToSqlContext GetContext() { GremlinToSqlContext inputContext = GetInputContext(); GremlinFreeVertexVariable newVariable = new GremlinFreeVertexVariable(); if (VertexIdsOrElements.Count > 0) { List <WBooleanExpression> booleanExprList = new List <WBooleanExpression>(); foreach (var id in VertexIdsOrElements) { if (id is int || id is string) { WScalarExpression firstExpr = newVariable.GetVariableProperty(GremlinKeyword.NodeID).ToScalarExpression(); WScalarExpression secondExpr = SqlUtil.GetValueExpr(id); WBooleanComparisonExpression booleanExpr = SqlUtil.GetEqualBooleanComparisonExpr(firstExpr, secondExpr); booleanExprList.Add(booleanExpr); } } inputContext.AddPredicate(SqlUtil.ConcatBooleanExprWithOr(booleanExprList)); } inputContext.VariableList.Add(newVariable); inputContext.TableReferences.Add(newVariable); inputContext.SetPivotVariable(newVariable); return(inputContext); }
internal override GremlinToSqlContext GetContext() { GremlinToSqlContext inputContext = GetInputContext(); if (inputContext.PivotVariable != null) { throw new QueryCompilationException("This step only can be a start step."); } GremlinFreeVertexVariable newVariable = new GremlinFreeVertexVariable(); inputContext.VariableList.Add(newVariable); inputContext.TableReferences.Add(newVariable); inputContext.SetPivotVariable(newVariable); inputContext.PivotVariable.OutE(inputContext, new List <string>()); if (EdgeIdsOrElements.Count > 0) { List <WBooleanExpression> booleanExprList = new List <WBooleanExpression>(); foreach (var id in EdgeIdsOrElements) { if (GremlinUtil.IsNumber(id) || id is string) { WScalarExpression firstExpr = inputContext.PivotVariable.GetVariableProperty(GremlinKeyword.EdgeID).ToScalarExpression(); WScalarExpression secondExpr = SqlUtil.GetValueExpr(id); WBooleanComparisonExpression booleanExpr = SqlUtil.GetEqualBooleanComparisonExpr(firstExpr, secondExpr); booleanExprList.Add(booleanExpr); } } inputContext.AddPredicate(SqlUtil.ConcatBooleanExprWithOr(booleanExprList)); } return(inputContext); }
internal virtual void HasNot(GremlinToSqlContext currentContext, string propertyKey) { GraphTraversal2 traversal2 = GraphTraversal2.__().Properties(propertyKey); traversal2.GetStartOp().InheritedVariableFromParent(currentContext); currentContext.AddPredicate(SqlUtil.GetNotExistPredicate(traversal2.GetEndOp().GetContext().ToSelectQueryBlock())); }
internal virtual void Is(GremlinToSqlContext currentContext, Predicate predicate) { WScalarExpression secondExpr = SqlUtil.GetValueExpr(predicate.Value); var firstExpr = DefaultVariableProperty().ToScalarExpression(); var booleanExpr = SqlUtil.GetBooleanComparisonExpr(firstExpr, secondExpr, predicate); currentContext.AddPredicate(booleanExpr); }
internal virtual void Or(GremlinToSqlContext currentContext, List <GremlinToSqlContext> orContexts) { List <WBooleanExpression> booleanExprList = new List <WBooleanExpression>(); foreach (var context in orContexts) { booleanExprList.Add(context.ToSqlBoolean()); } currentContext.AddPredicate(SqlUtil.ConcatBooleanExprWithOr(booleanExprList)); }
internal virtual void Where(GremlinToSqlContext currentContext, string startKey, Predicate predicate, TraversalRing traversalRing) { var selectKey = new List <string> { startKey }; var selectTraversal = new List <GraphTraversal2> { traversalRing.Next() }; var firstVar = GetSelectVar(currentContext, GremlinKeyword.Pop.Last, selectKey, selectTraversal); currentContext.AddPredicate(GetWherePredicate(currentContext, firstVar, predicate, traversalRing)); }
internal virtual void HasIdOrLabel(GremlinToSqlContext currentContext, GremlinHasType hasType, List <object> valuesOrPredicates) { GremlinVariableProperty variableProperty = hasType == GremlinHasType.HasId ? DefaultVariableProperty() : GetVariableProperty(GremlinKeyword.Label); List <WBooleanExpression> booleanExprList = new List <WBooleanExpression>(); foreach (var valuesOrPredicate in valuesOrPredicates) { booleanExprList.Add(CreateBooleanExpression(variableProperty, valuesOrPredicate)); } currentContext.AddPredicate(SqlUtil.ConcatBooleanExprWithOr(booleanExprList)); }
internal virtual void Where(GremlinToSqlContext currentContext, Predicate predicate) { var compareVar = currentContext.Select(predicate.Value as string); if (compareVar.Count > 1) { throw new Exception(); } var firstExpr = DefaultProjection().ToScalarExpression(); var secondExpr = compareVar.First().DefaultProjection().ToScalarExpression(); var booleanExpr = SqlUtil.GetBooleanComparisonExpr(firstExpr, secondExpr, predicate); currentContext.AddPredicate(booleanExpr); }
/// <summary> /// Only valid for VertexProperty /// </summary> internal virtual void HasKeyOrValue(GremlinToSqlContext currentContext, GremlinHasType hasType, List <object> valuesOrPredicates) { GraphTraversal2 traversal2 = hasType == GremlinHasType.HasKey ? GraphTraversal2.__().Key() : GraphTraversal2.__().Value(); traversal2.GetStartOp().InheritedVariableFromParent(currentContext); GremlinToSqlContext existContext = traversal2.GetEndOp().GetContext(); List <WBooleanExpression> booleanExprList = new List <WBooleanExpression>(); GremlinVariableProperty defaultVariableProperty = existContext.PivotVariable.DefaultProjection(); foreach (var valuesOrPredicate in valuesOrPredicates) { booleanExprList.Add(CreateBooleanExpression(defaultVariableProperty, valuesOrPredicate)); } existContext.AddPredicate(SqlUtil.ConcatBooleanExprWithOr(booleanExprList)); currentContext.AddPredicate(SqlUtil.GetExistPredicate(existContext.ToSelectQueryBlock())); }
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; }
internal override GremlinToSqlContext GetContext() { GremlinToSqlContext inputContext = GetInputContext(); if (inputContext.PivotVariable == null) { throw new QueryCompilationException("The PivotVariable 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.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 virtual void Or(GremlinToSqlContext currentContext, List <GremlinToSqlContext> orContexts) { List <WBooleanExpression> booleanExprList = orContexts.Select(context => context.ToSqlBoolean()).ToList(); currentContext.AddPredicate(SqlUtil.ConcatBooleanExprWithOr(booleanExprList)); }
internal virtual void Where(GremlinToSqlContext currentContext, Predicate predicate, TraversalRing traversalRing) { currentContext.AddPredicate(GetWherePredicate(currentContext, this, predicate, traversalRing)); }
internal virtual void Not(GremlinToSqlContext currentContext, GremlinToSqlContext notContext) { WBooleanExpression booleanExpr = SqlUtil.GetNotExistPredicate(notContext.ToSelectQueryBlock()); currentContext.AddPredicate(booleanExpr); }
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 virtual void Where(GremlinToSqlContext currentContext, GremlinToSqlContext whereContext) { WBooleanExpression wherePredicate = whereContext.ToSqlBoolean(); currentContext.AddPredicate(wherePredicate); }
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); }
internal virtual void Has(GremlinToSqlContext currentContext, string propertyKey, object valuesOrPredicate) { currentContext.AddPredicate(CreateBooleanExpression(GetVariableProperty(propertyKey), valuesOrPredicate)); }