Exemplo n.º 1
0
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();
            bool isList = false;

            if (GremlinUtil.IsList(ConstantValue) || GremlinUtil.IsArray(ConstantValue))
            {
                isList = true;  //1 It's a list
                foreach (var value in (IEnumerable)ConstantValue)
                {
                    parameters.Add(SqlUtil.GetValueExpr(value));
                }
            }
            else if (GremlinUtil.IsNumber(ConstantValue) || ConstantValue is string || ConstantValue is bool)
            {
                parameters.Add(SqlUtil.GetValueExpr(ConstantValue));
            }
            else
            {
                throw new ArgumentException();
            }
            var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Constant, parameters, GetVariableName());

            ((WConstantReference)tableRef).IsList = isList;
            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
 internal static bool IsInjectable(object injection)
 {
     if (GremlinUtil.IsList(injection) ||
         GremlinUtil.IsArray(injection) ||
         GremlinUtil.IsNumber(injection) ||
         injection is string ||
         injection is bool)
     {
         return(true);
     }
     else
     {
         throw new ArgumentException();
     }
 }
Exemplo n.º 4
0
 public GraphTraversal2 Constant(object value)
 {
     if (GremlinUtil.IsList(value) ||
         GremlinUtil.IsArray(value) ||
         GremlinUtil.IsNumber(value) ||
         value is string ||
         value is bool)
     {
         this.AddOperator(new GremlinConstantOp(value));
     }
     else
     {
         throw new ArgumentException();
     }
     return(this);
 }
Exemplo n.º 5
0
        internal override GremlinToSqlContext GetContext()
        {
            GremlinToSqlContext inputContext = GetInputContext();

            GremlinTableVariable newVariable;

            if (inputContext.PivotVariable == null ||
                inputContext.PivotVariable is GremlinFreeVertexVariable ||
                inputContext.PivotVariable is GremlinContextVariable)
            {
                newVariable = new GremlinFreeVertexVariable();
            }
            else
            {
                newVariable = new GremlinBoundVertexVariable();
            }

            if (VertexIdsOrElements.Count > 0)
            {
                List <WBooleanExpression> booleanExprList = new List <WBooleanExpression>();
                foreach (var id in VertexIdsOrElements)
                {
                    if (GremlinUtil.IsNumber(id) || id is string)
                    {
                        WScalarExpression firstExpr =
                            newVariable.GetVariableProperty(GremlinKeyword.NodeID).ToScalarExpression();
                        WScalarExpression            secondExpr  = SqlUtil.GetValueExpr(id);
                        WBooleanComparisonExpression booleanExpr = SqlUtil.GetEqualBooleanComparisonExpr(firstExpr,
                                                                                                         secondExpr);
                        booleanExprList.Add(booleanExpr);
                    }
                    else
                    {
                        throw new ArgumentException();
                    }
                }
                inputContext.AddPredicate(SqlUtil.ConcatBooleanExprWithOr(booleanExprList));
            }

            inputContext.VariableList.Add(newVariable);
            inputContext.TableReferencesInFromClause.Add(newVariable);
            inputContext.SetPivotVariable(newVariable);

            return(inputContext);
        }
Exemplo n.º 6
0
        private WBooleanExpression CreateBooleanExpression(GremlinVariableProperty variableProperty, object valuesOrPredicate)
        {
            if (valuesOrPredicate is string || GremlinUtil.IsNumber(valuesOrPredicate) || valuesOrPredicate is bool)
            {
                WScalarExpression firstExpr  = variableProperty.ToScalarExpression();
                WScalarExpression secondExpr = SqlUtil.GetValueExpr(valuesOrPredicate);
                return(SqlUtil.GetEqualBooleanComparisonExpr(firstExpr, secondExpr));
            }

            var predicate = valuesOrPredicate as Predicate;

            if (predicate != null)
            {
                WScalarExpression firstExpr  = variableProperty.ToScalarExpression();
                WScalarExpression secondExpr = SqlUtil.GetValueExpr(predicate.Value);
                return(SqlUtil.GetBooleanComparisonExpr(firstExpr, secondExpr, predicate));
            }

            throw new ArgumentException();
        }
Exemplo n.º 7
0
        public override WTableReference ToTableReference()
        {
            List <WScalarExpression> parameters = new List <WScalarExpression>();

            if (InputVariable == null)
            {
                //g.Inject()
                parameters.Add(SqlUtil.GetValueExpr(null));
            }
            else
            {
                parameters.Add(InputVariable.GetDefaultProjection().ToScalarExpression());
            }

            bool isList = false;

            if (GremlinUtil.IsList(Injection) || GremlinUtil.IsArray(Injection))
            {
                isList = true;  //1 It's a list
                foreach (var value in (IEnumerable)Injection)
                {
                    parameters.Add(SqlUtil.GetValueExpr(value));
                }
            }
            else if (GremlinUtil.IsNumber(Injection) || Injection is string || Injection is bool)
            {
                parameters.Add(SqlUtil.GetValueExpr(Injection));
            }
            else
            {
                throw new ArgumentException();
            }

            var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Inject, parameters, GetVariableName());

            ((WInjectTableReference)tableRef).IsList = isList;
            return(SqlUtil.GetCrossApplyTableReference(tableRef));
        }
Exemplo n.º 8
0
        public GraphTraversal2 Option(object pickToken, GraphTraversal2 traversalOption)
        {
            if (!(GremlinUtil.IsNumber(pickToken) || pickToken is string || pickToken is GremlinKeyword.Pick || pickToken is bool))
            {
                throw new ArgumentException();
            }
            var op = GetEndOp() as GremlinChooseOp;

            if (op != null)
            {
                if (op.Options.ContainsKey(pickToken))
                {
                    throw new SyntaxErrorException(
                              $"Choose step can only have one traversal per pick token: {pickToken}");
                }
                op.Options[pickToken] = traversalOption;
                return(this);
            }
            else
            {
                throw new Exception("Option step only can follow by choose step.");
            }
        }