Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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()));
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        /// <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()));
        }
Ejemplo n.º 5
0
        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);
        }