internal override GremlinToSqlContext GetContext() { GremlinToSqlContext inputContext = GetInputContext(); if (inputContext.PivotVariable == null) { throw new QueryCompilationException("The PivotVariable can't be null."); } if (this.ByModulatingList.Count == 0) { this.ByModulatingList.Add(new Tuple <GraphTraversal2, IComparer>(GraphTraversal2.__(), new IncrOrder())); } var newByModulatingList = new List <Tuple <GremlinToSqlContext, IComparer> >(); foreach (var pair in this.ByModulatingList) { GraphTraversal2 traversal = pair.Item1; GremlinToSqlContext context = null; //g.V().groupCount().order(Local).by(Keys) or g.V().groupCount().order(Local).by(__.select(Keys)) if (traversal.TranslationOpList.Count >= 2 && traversal.TranslationOpList[1] is GremlinSelectColumnOp) { //FROM selectColumn(C._value, "Keys"/"Values") GremlinToSqlContext newContext = new GremlinToSqlContext(); GremlinOrderLocalInitVariable initVar = new GremlinOrderLocalInitVariable(); newContext.VariableList.Add(initVar); newContext.SetPivotVariable(initVar); traversal.GetStartOp().InheritedContextFromParent(newContext); context = traversal.GetEndOp().GetContext(); } else { //FROM decompose1(C._value) GremlinToSqlContext newContext = new GremlinToSqlContext(); GremlinDecompose1Variable decompose1 = new GremlinDecompose1Variable(inputContext.PivotVariable); newContext.VariableList.Add(decompose1); newContext.TableReferences.Add(decompose1); newContext.SetPivotVariable(decompose1); traversal.GetStartOp().InheritedContextFromParent(newContext); context = traversal.GetEndOp().GetContext(); } newByModulatingList.Add(new Tuple <GremlinToSqlContext, IComparer>(context, pair.Item2)); } inputContext.PivotVariable.OrderLocal(inputContext, newByModulatingList); 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 override GremlinToSqlContext GetContext() { GremlinToSqlContext inputContext = GetInputContext(); if (inputContext.PivotVariable == null) { throw new QueryCompilationException("The PivotVariable can't be null."); } if (this.ByModulatingList.Count == 0) { this.ByModulatingList.Add(new Tuple <GraphTraversal2, IComparer>(GraphTraversal2.__(), new IncrOrder())); } var newByModulatingList = new List <Tuple <GremlinToSqlContext, IComparer> >(); foreach (var pair in this.ByModulatingList) { GraphTraversal2 traversal = pair.Item1; GremlinToSqlContext context = null; traversal.GetStartOp().InheritedVariableFromParent(inputContext); context = traversal.GetEndOp().GetContext(); newByModulatingList.Add(new Tuple <GremlinToSqlContext, IComparer>(context, pair.Item2)); } inputContext.PivotVariable.OrderGlobal(inputContext, newByModulatingList); return(inputContext); }
internal void ConfigureStartAndEndSteps(GraphTraversal2 whereTraversal) { if (whereTraversal.TranslationOpList.Count >= 2) { //__.as() GremlinAsOp asOp = whereTraversal.TranslationOpList[1] as GremlinAsOp; if (asOp != null) { whereTraversal.TranslationOpList.RemoveAt(1); //remove as-step whereTraversal.InsertOperator(1, new GremlinSelectOp(GremlinKeyword.Pop.Last, asOp.Labels.First())); } //__.Or() GremlinOrOp orOp = whereTraversal.TranslationOpList[1] as GremlinOrOp; if (orOp != null) { foreach (var traversal in orOp.OrTraversals) { ConfigureStartAndEndSteps(traversal); } } //__.And() GremlinAndOp andOp = whereTraversal.TranslationOpList[1] as GremlinAndOp; if (andOp != null) { foreach (var traversal in andOp.AndTraversals) { ConfigureStartAndEndSteps(traversal); } } //__.Not() GremlinNotOp notOp = whereTraversal.TranslationOpList[1] as GremlinNotOp; if (notOp != null) { ConfigureStartAndEndSteps(notOp.NotTraversal); } } var lastOp = WhereTraversal.GetEndOp() as GremlinAsOp; if (lastOp != null) { string label = lastOp.Labels.First(); whereTraversal.TranslationOpList.Remove(whereTraversal.GetEndOp()); //remove the last as-step whereTraversal.AddOperator(new GremlinWherePredicateOp(Predicate.eq(label))); } }
/// <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 virtual void DedupGlobal(GremlinToSqlContext currentContext, List <string> dedupLabels, GraphTraversal2 dedupTraversal) { List <GremlinVariable> dedupVariables = new List <GremlinVariable>(); foreach (var dedupLabel in dedupLabels) { dedupVariables.Add(GetSelectVar(currentContext, GremlinKeyword.Pop.Last, new List <string> { dedupLabel }, new List <GraphTraversal2>() { dedupTraversal.Copy() })); } dedupTraversal.GetStartOp().InheritedVariableFromParent(currentContext); GremlinToSqlContext dedupContext = dedupTraversal.GetEndOp().GetContext(); GremlinDedupGlobalVariable newVariable = new GremlinDedupGlobalVariable(this, dedupVariables, dedupContext); currentContext.VariableList.Add(newVariable); currentContext.TableReferences.Add(newVariable); }