示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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));
        }
示例#4
0
        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));
        }
示例#5
0
        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));
        }
示例#6
0
        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)));
        }
示例#7
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()));
        }
示例#8
0
        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));
        }
示例#9
0
        internal virtual void Or(GremlinToSqlContext currentContext, List <GremlinToSqlContext> orContexts)
        {
            List <WBooleanExpression> booleanExprList = orContexts.Select(context => context.ToSqlBoolean()).ToList();

            currentContext.AddPredicate(SqlUtil.ConcatBooleanExprWithOr(booleanExprList));
        }