示例#1
0
        internal override GraphViewExecutionOperator Compile(QueryCompilationContext context, GraphViewConnection dbConnection)
        {
            WScalarSubquery srcSubQuery  = this.Parameters[0] as WScalarSubquery;
            WScalarSubquery sinkSubQuery = this.Parameters[1] as WScalarSubquery;

            if (srcSubQuery == null || sinkSubQuery == null)
            {
                throw new SyntaxErrorException("The first two parameters of AddE can only be WScalarSubquery.");
            }
            WValueExpression otherVTagParameter = this.Parameters[2] as WValueExpression;
            WValueExpression edgeLabel          = this.Parameters[3] as WValueExpression;

            Debug.Assert(otherVTagParameter != null, "otherVTagParameter != null");
            //
            // if otherVTag == 0, this newly added edge's otherV() is the src vertex.
            // Otherwise, it's the sink vertex
            //
            int otherVTag = int.Parse(otherVTagParameter.Value);

            List <WPropertyExpression> edgeProperties = new List <WPropertyExpression>();
            List <string> projectedField = new List <string>();

            for (int i = 4; i < this.Parameters.Count; i += 1)
            {
                WPropertyExpression addedProperty = this.Parameters[i] as WPropertyExpression;
                if (addedProperty != null)
                {
                    edgeProperties.Add(addedProperty);
                }

                WValueExpression projectedProperty = this.Parameters[i] as WValueExpression;
                if (projectedProperty != null)
                {
                    projectedField.Add(projectedProperty.Value);
                }
            }
            JObject edgeJsonObject = this.ConstructEdgeJsonObject(edgeLabel, edgeProperties);

            QueryCompilationContext    srcSubContext = new QueryCompilationContext(context);
            GraphViewExecutionOperator srcSubQueryOp = srcSubQuery.SubQueryExpr.Compile(srcSubContext, dbConnection);

            QueryCompilationContext    sinkSubContext = new QueryCompilationContext(context);
            GraphViewExecutionOperator sinkSubQueryOp = sinkSubQuery.SubQueryExpr.Compile(sinkSubContext, dbConnection);

            GraphViewExecutionOperator addEOp = new AddEOperator(context.CurrentExecutionOperator, dbConnection,
                                                                 srcSubContext.OuterContextOp, srcSubQueryOp, sinkSubContext.OuterContextOp, sinkSubQueryOp,
                                                                 otherVTag, edgeJsonObject, projectedField);

            context.CurrentExecutionOperator = addEOp;

            foreach (string propertyName in projectedField)
            {
                ColumnGraphType columnGraphType = GraphViewReservedProperties.IsEdgeReservedProperty(propertyName)
                    ? GraphViewReservedProperties.ReservedEdgePropertiesColumnGraphTypes[propertyName]
                    : ColumnGraphType.Value;
                context.AddField(this.Alias.Value, propertyName, columnGraphType);
            }

            return(addEOp);
        }
        /// <summary>
        /// Adds a new field to the raw records when a new execution operator is added to the execution plan.
        /// </summary>
        /// <param name="tableAlias"></param>
        /// <param name="columnName"></param>
        /// <param name="type"></param>
        public void AddField(string tableAlias, string columnName, ColumnGraphType type)
        {
            int index = RawRecordLayout.Count;
            WColumnReferenceExpression colRef = new WColumnReferenceExpression(tableAlias, columnName);

            colRef.ColumnGraphType  = type;
            RawRecordLayout[colRef] = index;
        }
示例#3
0
        internal override GraphViewExecutionOperator Compile(QueryCompilationContext context, GraphViewConnection dbConnection)
        {
            //
            // Parameters:
            //   #1 <WValueExpression>: Vertex label
            //   ... <WPropertyExpression>: The initial properties on vertex
            //   ... <WValueExpression>: The projected field of AddV

            WValueExpression labelValue = (WValueExpression)this.Parameters[0];

            List <WPropertyExpression> vertexProperties = new List <WPropertyExpression>();
            List <string> projectedField = new List <string>();

            for (int i = 1; i < this.Parameters.Count; i++)
            {
                WPropertyExpression addedProperty = this.Parameters[i] as WPropertyExpression;
                if (addedProperty != null)
                {
                    vertexProperties.Add(addedProperty);
                }

                WValueExpression projectedProperty = this.Parameters[i] as WValueExpression;
                if (projectedProperty != null)
                {
                    projectedField.Add(projectedProperty.Value);
                }
                //Debug.Assert(property != null, "[WAddVTableReference.Compile] Vertex property should not be null");
                //Debug.Assert(property.Cardinality == GremlinKeyword.PropertyCardinality.List, "[WAddVTableReference.Compile] Vertex property should be append-mode");
                //Debug.Assert(property.Value != null);
            }

            JObject nodeJsonDocument = this.ConstructNodeJsonDocument(labelValue.Value, vertexProperties);

            AddVOperator addVOp = new AddVOperator(
                context.CurrentExecutionOperator,
                dbConnection,
                nodeJsonDocument,
                projectedField);

            context.CurrentExecutionOperator = addVOp;

            foreach (string propertyName in projectedField)
            {
                ColumnGraphType columnGraphType = GraphViewReservedProperties.IsNodeReservedProperty(propertyName)
                    ? GraphViewReservedProperties.ReservedNodePropertiesColumnGraphTypes[propertyName]
                    : ColumnGraphType.Value;
                context.AddField(this.Alias.Value, propertyName, columnGraphType);
            }

            return(addVOp);
        }
示例#4
0
        public WColumnReferenceExpression(string tableName, string columnName, ColumnGraphType columnGraphType)
        {
            ColumnType      = ColumnType.Regular;
            ColumnGraphType = columnGraphType;

            Identifier tableIdent = tableName != null ? new Identifier {
                Value = tableName
            } : null;
            Identifier columnIdent = columnName != null ? new Identifier {
                Value = columnName
            } : null;

            MultiPartIdentifier = new WMultiPartIdentifier(tableIdent, columnIdent);
        }
示例#5
0
        /// <summary>
        /// Adds a new field to the raw records when a new execution operator is added to the execution plan.
        /// </summary>
        /// <param name="tableAlias"></param>
        /// <param name="columnName"></param>
        /// <param name="type"></param>
        /// <param name="insertAtFront"></param>
        public void AddField(string tableAlias, string columnName, ColumnGraphType type, bool insertAtFront = false)
        {
            WColumnReferenceExpression colRef = new WColumnReferenceExpression(tableAlias, columnName);

            colRef.ColumnGraphType = type;

            if (insertAtFront)
            {
                foreach (WColumnReferenceExpression column in this.RawRecordLayout.Keys.ToList())
                {
                    ++this.RawRecordLayout[column];
                    if (this.ParentContextRawRecordLayout != null && this.ParentContextRawRecordLayout.ContainsKey(column))
                    {
                        ++this.ParentContextRawRecordLayout[column];
                    }
                }
                this.RawRecordLayout[colRef] = 0;
            }
            else
            {
                int index = this.RawRecordLayout.Count;
                this.RawRecordLayout[colRef] = index;
            }
        }
        internal override GraphViewExecutionOperator Compile(QueryCompilationContext context, GraphViewCommand command)
        {
            //
            // Parameters:
            //   #1 <WValueExpression>: Vertex label
            //   ... <WPropertyExpression>: The initial properties on vertex
            //

            WValueExpression labelValue = (WValueExpression)this.Parameters[0];

            Debug.Assert(labelValue.Value != null, "[WAddVTableReference.Compile] Vertex label should not be null");

            List <PropertyTuple> vertexProperties = new List <PropertyTuple>();

            List <string> projectedField = new List <string>(GraphViewReservedProperties.InitialPopulateNodeProperties);

            projectedField.Add(GremlinKeyword.Star);
            projectedField.Add(GremlinKeyword.Label);


            for (int i = 1; i < this.Parameters.Count; i++)
            {
                WPropertyExpression property = (WPropertyExpression)this.Parameters[i];
                Debug.Assert(property != null, "[WAddVTableReference.Compile] Vertex property should not be null");
                Debug.Assert(property.Cardinality == GremlinKeyword.PropertyCardinality.List, "[WAddVTableReference.Compile] Vertex property should be append-mode");
                Debug.Assert(property.Value != null);

                if (!projectedField.Contains(property.Key.Value))
                {
                    projectedField.Add(property.Key.Value);
                }

                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);
                    vertexProperties.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);
                    vertexProperties.Add(valueProperty);
                }
            }

            JObject nodeJsonDocument = ConstructNodeJsonDocument(command, labelValue.Value);

            AddVOperator addVOp = new AddVOperator(
                context.CurrentExecutionOperator,
                command,
                nodeJsonDocument,
                projectedField,
                vertexProperties);

            context.CurrentExecutionOperator = addVOp;

            for (int i = 0; i < projectedField.Count; i++)
            {
                string          propertyName    = projectedField[i];
                ColumnGraphType columnGraphType = GraphViewReservedProperties.IsNodeReservedProperty(propertyName)
                    ? GraphViewReservedProperties.ReservedNodePropertiesColumnGraphTypes[propertyName]
                    : ColumnGraphType.Value;
                context.AddField(Alias.Value, propertyName, columnGraphType);
            }

            // Convert the connection to Hybrid if necessary
            if (command.Connection.GraphType != GraphType.GraphAPIOnly)
            {
                command.Connection.GraphType = GraphType.Hybrid;
            }

            return(addVOp);
        }
 public void AddColumn(string columnName, ColumnGraphType ptype, int index)
 {
     // If the same column name has appeared before, the newly defined column
     // will override the older one and the older one will not be accessible.
     columnSet[columnName] = new Tuple <int, ColumnGraphType>(index, ptype);
 }