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 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 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 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 void HasLabel(GremlinVariable lastVariable, List <object> values) { List <WBooleanExpression> booleanExprList = new List <WBooleanExpression>(); foreach (var value in values) { WScalarExpression firstExpr = lastVariable.GetVariableProperty(GremlinKeyword.Label).ToScalarExpression(); WScalarExpression secondExpr = SqlUtil.GetValueExpr(value); booleanExprList.Add(SqlUtil.GetEqualBooleanComparisonExpr(firstExpr, secondExpr)); } WBooleanExpression concatSql = SqlUtil.ConcatBooleanExprWithOr(booleanExprList); AddPredicate(SqlUtil.GetBooleanParenthesisExpr(concatSql)); }
internal void AddLabelPredicateForEdge(GremlinEdgeTableVariable edgeTable, List <string> edgeLabels) { if (edgeLabels.Count == 0) { return; } List <WBooleanExpression> booleanExprList = new List <WBooleanExpression>(); foreach (var edgeLabel in edgeLabels) { var firstExpr = edgeTable.GetVariableProperty(GremlinKeyword.Label).ToScalarExpression(); var secondExpr = SqlUtil.GetValueExpr(edgeLabel); booleanExprList.Add(SqlUtil.GetEqualBooleanComparisonExpr(firstExpr, secondExpr)); } AddPredicate(SqlUtil.GetBooleanParenthesisExpr(SqlUtil.ConcatBooleanExprWithOr(booleanExprList))); }
/// <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 WBooleanExpression GetWherePredicate(GremlinToSqlContext currentContext, GremlinVariable firstVar, Predicate predicate, TraversalRing traversalRing) { AndPredicate andPredicate = predicate as AndPredicate; if (andPredicate != null) { List <WBooleanExpression> booleanList = new List <WBooleanExpression>(); foreach (var p in andPredicate.PredicateList) { booleanList.Add(GetWherePredicate(currentContext, firstVar, p, traversalRing)); } return(SqlUtil.ConcatBooleanExprWithAnd(booleanList)); } OrPredicate orPredicate = predicate as OrPredicate; if (orPredicate != null) { List <WBooleanExpression> booleanList = new List <WBooleanExpression>(); foreach (var p in orPredicate.PredicateList) { booleanList.Add(GetWherePredicate(currentContext, firstVar, p, traversalRing)); } return(SqlUtil.ConcatBooleanExprWithOr(booleanList)); } var selectKeys = new List <string>() { predicate.Value as string }; var selectTraversal = new List <GraphTraversal2>() { traversalRing.Next() }; var selectVar = GetSelectVar(currentContext, GremlinKeyword.Pop.Last, selectKeys, selectTraversal); var firstExpr = firstVar.GetDefaultProjection().ToScalarExpression(); var secondExpr = selectVar.GetDefaultProjection().ToScalarExpression(); return(SqlUtil.GetBooleanComparisonExpr(firstExpr, secondExpr, predicate)); }
internal virtual void Or(GremlinToSqlContext currentContext, List <GremlinToSqlContext> orContexts) { List <WBooleanExpression> booleanExprList = orContexts.Select(context => context.ToSqlBoolean()).ToList(); currentContext.AddPredicate(SqlUtil.ConcatBooleanExprWithOr(booleanExprList)); }