Example #1
0
        private GremlinPathVariable generatePath(GremlinToSqlContext currentContext, List <GraphTraversal2> byList = null)
        {
            List <GremlinToSqlContext>     byContexts = new List <GremlinToSqlContext>();
            List <GremlinPathStepVariable> steps      = currentContext.GetGremlinStepList();

            if (byList == null)
            {
                byList = new List <GraphTraversal2> {
                    GraphTraversal2.__()
                };
            }

            foreach (var by in byList)
            {
                GremlinToSqlContext       newContext = new GremlinToSqlContext();
                GremlinDecompose1Variable decompose1 = new GremlinDecompose1Variable(steps);
                newContext.VariableList.Add(decompose1);
                newContext.TableReferences.Add(decompose1);
                newContext.SetPivotVariable(decompose1);

                by.GetStartOp().InheritedContextFromParent(newContext);
                byContexts.Add(by.GetEndOp().GetContext());
            }

            GremlinPathVariable newVariable = new GremlinPathVariable(steps, byContexts);

            currentContext.VariableList.Add(newVariable);
            currentContext.TableReferences.Add(newVariable);

            return(newVariable);
        }
Example #2
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);
        }
Example #3
0
        internal virtual GremlinSelectVariable GetSelectVar(GremlinToSqlContext currentContext, GremlinKeyword.Pop pop, List <string> selectKeys, List <GraphTraversal2> byList = null)
        {
            //TODO: refactor
            if (byList == null)
            {
                byList = new List <GraphTraversal2>()
                {
                    GraphTraversal2.__()
                };
            }
            List <GremlinToSqlContext> byContexts          = new List <GremlinToSqlContext>();
            List <GremlinVariable>     steps               = currentContext.GetGlobalPathStepList();
            List <GremlinVariable>     sideEffectVariables = currentContext.GetSideEffectVariables();

            GremlinGlobalPathVariable pathVariable = new GremlinGlobalPathVariable(steps);

            currentContext.VariableList.Add(pathVariable);
            currentContext.TableReferences.Add(pathVariable);

            foreach (var by in byList)
            {
                GremlinToSqlContext       newContext = new GremlinToSqlContext();
                GremlinDecompose1Variable decompose1 = new GremlinDecompose1Variable(pathVariable);
                newContext.VariableList.Add(decompose1);
                newContext.TableReferences.Add(decompose1);
                newContext.SetPivotVariable(decompose1);

                by.GetStartOp().InheritedContextFromParent(newContext);
                byContexts.Add(by.GetEndOp().GetContext());
            }

            GremlinSelectVariable newVariable = new GremlinSelectVariable(this, pathVariable, sideEffectVariables, pop, selectKeys, byContexts);

            currentContext.VariableList.Add(newVariable);
            currentContext.TableReferences.Add(newVariable);

            return(newVariable);
        }