Esempio n. 1
0
        internal override GraphViewExecutionOperator Compile(QueryCompilationContext context, GraphViewConnection dbConnection)
        {
            var srcIdParameter      = Parameters[0] as WColumnReferenceExpression;
            var edgeOffsetParameter = Parameters[1] as WColumnReferenceExpression;
            var srcIdIndex          = context.LocateColumnReference(srcIdParameter);
            var edgeOffsetIndex     = context.LocateColumnReference(edgeOffsetParameter);
            var edgeAlias           = edgeOffsetParameter.TableReference;
            var propertiesList      = new List <Tuple <WValueExpression, WValueExpression, int> >();

            for (var i = 2; i < Parameters.Count; i += 2)
            {
                var keyExpression   = Parameters[i] as WValueExpression;
                var valueExpression = Parameters[i + 1] as WValueExpression;

                int propertyIndex;
                if (!context.TryLocateColumnReference(new WColumnReferenceExpression(edgeAlias, keyExpression.Value), out propertyIndex))
                {
                    propertyIndex = -1;
                }

                propertiesList.Add(new Tuple <WValueExpression, WValueExpression, int>(keyExpression, valueExpression, propertyIndex));
            }

            var updateEdgePropertiesOp = new UpdateEdgePropertiesOperator(context.CurrentExecutionOperator, dbConnection,
                                                                          srcIdIndex, edgeOffsetIndex, propertiesList);

            context.CurrentExecutionOperator = updateEdgePropertiesOp;

            return(updateEdgePropertiesOp);
        }
Esempio n. 2
0
        internal override GraphViewExecutionOperator Compile(QueryCompilationContext context, GraphViewConnection dbConnection)
        {
            var srcIdParameter      = Parameters[0] as WColumnReferenceExpression;
            var edgeOffsetParameter = Parameters[1] as WColumnReferenceExpression;
            var srcIdIndex          = context.LocateColumnReference(srcIdParameter);
            var edgeOffsetIndex     = context.LocateColumnReference(edgeOffsetParameter);

            var dropEdgeOp = new DropEdgeOperator(context.CurrentExecutionOperator, dbConnection, srcIdIndex, edgeOffsetIndex);

            context.CurrentExecutionOperator = dropEdgeOp;

            return(dropEdgeOp);
        }
Esempio n. 3
0
        internal override GraphViewExecutionOperator Compile(QueryCompilationContext context, GraphViewCommand command)
        {
            var dropTargetParameter = Parameters[0] as WColumnReferenceExpression;
            var dropTargetIndex     = context.LocateColumnReference(dropTargetParameter);

            List <string> populateColumns = new List <string>()
            {
                GremlinKeyword.TableDefaultColumnName
            };

            for (int i = 1; i < this.Parameters.Count; i++)
            {
                WValueExpression populateColumn = this.Parameters[i] as WValueExpression;
                Debug.Assert(populateColumn != null, "populateColumn != null");
                populateColumns.Add(populateColumn.Value);
            }

            var dropOp = new DropOperator(context.CurrentExecutionOperator, command, dropTargetIndex);

            context.CurrentExecutionOperator = dropOp;
            foreach (string columnName in populateColumns)
            {
                context.AddField(Alias.Value, columnName, ColumnGraphType.Value);
            }

            return(dropOp);
        }
Esempio n. 4
0
        internal override ScalarFunction CompileToFunction(QueryCompilationContext context, GraphViewConnection dbConnection)
        {
            if (ColumnType == ColumnType.Wildcard)
            {
                return(null);
            }
            int fieldIndex = context.LocateColumnReference(this);

            return(new FieldValue(fieldIndex));
        }
Esempio n. 5
0
        internal GraphViewExecutionOperator Compile2(QueryCompilationContext context, GraphViewConnection dbConnection)
        {
            WColumnReferenceExpression dropTargetParameter = Parameters[0] as WColumnReferenceExpression;

            Debug.Assert(dropTargetParameter != null, "dropTargetParameter != null");
            int dropTargetIndex = context.LocateColumnReference(dropTargetParameter);

            //
            // A new DropOperator which drops target based on its runtime type
            //
            DropNodeOperator dropOp = new DropNodeOperator(context.CurrentExecutionOperator, dbConnection, dropTargetIndex);

            context.CurrentExecutionOperator = dropOp;

            return(dropOp);
        }
Esempio n. 6
0
        internal override GraphViewExecutionOperator Compile(QueryCompilationContext context, GraphViewConnection dbConnection)
        {
            WColumnReferenceExpression updateParameter = this.Parameters[0] as WColumnReferenceExpression;
            int updateIndex    = context.LocateColumnReference(updateParameter);
            var propertiesList = new List <WPropertyExpression>();

            for (int i = 1; i < this.Parameters.Count; ++i)
            {
                propertiesList.Add((WPropertyExpression)this.Parameters[i]);
#if DEBUG
                ((WPropertyExpression)this.Parameters[i]).Value.ToJValue();
#endif
            }

            UpdatePropertiesOperator updateOp = new UpdatePropertiesOperator(
                context.CurrentExecutionOperator,
                dbConnection,
                updateIndex,
                propertiesList);
            context.CurrentExecutionOperator = updateOp;

            return(updateOp);
        }
Esempio n. 7
0
        internal override ScalarFunction CompileToFunction(QueryCompilationContext context, GraphViewCommand command)
        {
            int fieldIndex = context.LocateColumnReference(this);

            return(new FieldValue(fieldIndex));
        }
Esempio n. 8
0
        internal override ScalarFunction CompileToFunction(QueryCompilationContext context, GraphViewCommand command)
        {
            string funcName = FunctionName.ToString().ToLowerInvariant();

            switch (funcName)
            {
            case "withinarray":
                WColumnReferenceExpression checkField = Parameters[0] as WColumnReferenceExpression;
                WColumnReferenceExpression arrayField = Parameters[1] as WColumnReferenceExpression;
                return(new WithInArray(context.LocateColumnReference(checkField), context.LocateColumnReference(arrayField)));

            case "withoutarray":
                checkField = Parameters[0] as WColumnReferenceExpression;
                arrayField = Parameters[1] as WColumnReferenceExpression;
                return(new WithOutArray(context.LocateColumnReference(checkField), context.LocateColumnReference(arrayField)));

            case "hasproperty":
                checkField = Parameters[0] as WColumnReferenceExpression;
                WValueExpression propertyName = Parameters[1] as WValueExpression;
                return(new HasProperty(context.LocateColumnReference(checkField), propertyName.Value));

            case "compose1":
                List <Tuple <string, int> > targetFieldsAndTheirNames = new List <Tuple <string, int> >();
                WValueExpression            defaultProjectionKey      = Parameters[1] as WValueExpression;
                if (defaultProjectionKey == null)
                {
                    throw new SyntaxErrorException("The first parameter of Compose1 has to be a WValueExpression.");
                }

                for (int i = 0; i < Parameters.Count; i += 2)
                {
                    WColumnReferenceExpression columnRef = Parameters[i] as WColumnReferenceExpression;
                    WValueExpression           name      = Parameters[i + 1] as WValueExpression;

                    if (name == null)
                    {
                        throw new SyntaxErrorException("The parameter of Compose1 at an even position has to be a WValueExpression.");
                    }
                    if (columnRef == null)
                    {
                        throw new SyntaxErrorException("The parameter of Compose1 at an odd position has to be a WColumnReference.");
                    }

                    targetFieldsAndTheirNames.Add(new Tuple <string, int>(name.Value, context.LocateColumnReference(columnRef)));
                }

                return(new ComposeCompositeField(targetFieldsAndTheirNames, defaultProjectionKey.Value));

            case "compose2":
                List <ScalarFunction> inputOfCompose2 = new List <ScalarFunction>();

                foreach (var parameter in Parameters)
                {
                    inputOfCompose2.Add(parameter.CompileToFunction(context, command));
                }

                return(new Compose2(inputOfCompose2));

            case "path":
                List <Tuple <ScalarFunction, bool, HashSet <string> > > pathStepList;
                List <ScalarFunction> byFuncList;
                WPathTableReference.GetPathStepListAndByFuncList(context, command, this.Parameters,
                                                                 out pathStepList, out byFuncList);
                return(new Path(pathStepList));

            default:
                throw new NotImplementedException("Function " + funcName + " hasn't been implemented.");
            }
            throw new NotImplementedException("Function " + funcName + " hasn't been implemented.");
        }
Esempio n. 9
0
        internal override GraphViewExecutionOperator Compile(QueryCompilationContext context, GraphViewCommand command)
        {
            WColumnReferenceExpression updateParameter = this.Parameters[0] as WColumnReferenceExpression;
            int updateIndex = context.LocateColumnReference(updateParameter);
            List <PropertyTuple> propertiesList = new List <PropertyTuple>();

            for (int i = 1; i < this.Parameters.Count; ++i)
            {
                WPropertyExpression property = this.Parameters[i] as WPropertyExpression;
                if (property.Value is WValueExpression)
                {
                    WValueExpression value = property.Value as WValueExpression;
                    Dictionary <string, Tuple <StringField, ScalarSubqueryFunction> > meta = new Dictionary <string, Tuple <StringField, ScalarSubqueryFunction> >();

                    foreach (KeyValuePair <WValueExpression, WScalarExpression> pair in property.MetaProperties)
                    {
                        string name = pair.Key.Value;
                        if (pair.Value is WValueExpression)
                        {
                            WValueExpression metaValue = pair.Value as WValueExpression;
                            meta.Add(name, new Tuple <StringField, ScalarSubqueryFunction>(metaValue.ToStringField(), null));
                        }
                        else
                        {
                            WScalarSubquery        metaScalarSubquery = pair.Value as WScalarSubquery;
                            ScalarSubqueryFunction metaValueFunction  = (ScalarSubqueryFunction)metaScalarSubquery.CompileToFunction(context, command);
                            meta.Add(name, new Tuple <StringField, ScalarSubqueryFunction>(null, metaValueFunction));
                        }
                    }

                    PropertyTuple valueProperty = new PropertyTuple(property.Cardinality, property.Key.Value, value.ToStringField(), meta);
                    propertiesList.Add(valueProperty);
                }
                else
                {
                    WScalarSubquery        scalarSubquery = property.Value as WScalarSubquery;
                    ScalarSubqueryFunction valueFunction  = (ScalarSubqueryFunction)scalarSubquery.CompileToFunction(context, command);

                    Dictionary <string, Tuple <StringField, ScalarSubqueryFunction> > meta = new Dictionary <string, Tuple <StringField, ScalarSubqueryFunction> >();
                    foreach (KeyValuePair <WValueExpression, WScalarExpression> pair in property.MetaProperties)
                    {
                        string name = pair.Key.Value;
                        if (pair.Value is WValueExpression)
                        {
                            WValueExpression metaValue = pair.Value as WValueExpression;
                            meta.Add(name, new Tuple <StringField, ScalarSubqueryFunction>(metaValue.ToStringField(), null));
                        }
                        else
                        {
                            WScalarSubquery        metaScalarSubquery = pair.Value as WScalarSubquery;
                            ScalarSubqueryFunction metaValueFunction  = (ScalarSubqueryFunction)metaScalarSubquery.CompileToFunction(context, command);
                            meta.Add(name, new Tuple <StringField, ScalarSubqueryFunction>(null, metaValueFunction));
                        }
                    }

                    PropertyTuple valueProperty = new PropertyTuple(property.Cardinality, property.Key.Value, valueFunction, meta);
                    propertiesList.Add(valueProperty);
                }
            }

            UpdatePropertiesOperator updateOp = new UpdatePropertiesOperator(
                context.CurrentExecutionOperator,
                command,
                updateIndex,
                propertiesList);

            context.CurrentExecutionOperator = updateOp;

            return(updateOp);
        }