Beispiel #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);
        }
Beispiel #2
0
        internal override GraphViewExecutionOperator Compile(QueryCompilationContext context, GraphViewConnection dbConnection)
        {
            List <string> projectedField;
            var           edgeJsonObject = ConstructEdgeJsonObject(out projectedField); // metadata remains missing

            var srcSubQuery  = Parameters[0] as WScalarSubquery;
            var sinkSubQuery = Parameters[1] as WScalarSubquery;

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

            var srcSubQueryFunction  = srcSubQuery.CompileToFunction(context, dbConnection);
            var sinkSubQueryFunction = sinkSubQuery.CompileToFunction(context, dbConnection);

            GraphViewExecutionOperator addEOp = new AddEOperator(context.CurrentExecutionOperator,
                                                                 dbConnection, srcSubQueryFunction, sinkSubQueryFunction, otherVTag, edgeJsonObject, projectedField);

            context.CurrentExecutionOperator = addEOp;

            // Update context's record layout
            context.AddField(Alias.Value, "_source", ColumnGraphType.EdgeSource);
            context.AddField(Alias.Value, "_sink", ColumnGraphType.EdgeSink);
            context.AddField(Alias.Value, "_other", ColumnGraphType.Value);
            context.AddField(Alias.Value, "_offset", ColumnGraphType.EdgeOffset);
            context.AddField(Alias.Value, "*", ColumnGraphType.EdgeObject);
            for (var i = GraphViewReservedProperties.ReservedEdgeProperties.Count; i < projectedField.Count; i++)
            {
                context.AddField(Alias.Value, projectedField[i], ColumnGraphType.Value);
            }

            return(addEOp);
        }
        internal override GraphViewExecutionOperator Compile(QueryCompilationContext context, GraphViewCommand command)
        {
            WScalarSubquery srcSubQuery  = Parameters[0] as WScalarSubquery;
            WScalarSubquery sinkSubQuery = Parameters[1] as WScalarSubquery;

            if (srcSubQuery == null || sinkSubQuery == null)
            {
                throw new SyntaxErrorException("The first two parameters of AddE can only be WScalarSubquery.");
            }

            Container container = new Container();
            QueryCompilationContext srcSubContext = new QueryCompilationContext(context);

            srcSubContext.OuterContextOp.SetContainer(container);
            GraphViewExecutionOperator srcSubQueryOp = srcSubQuery.SubQueryExpr.Compile(srcSubContext, command);

            QueryCompilationContext sinkSubContext = new QueryCompilationContext(context);

            sinkSubContext.OuterContextOp.SetContainer(container);
            GraphViewExecutionOperator sinkSubQueryOp = sinkSubQuery.SubQueryExpr.Compile(sinkSubContext, command);

            WValueExpression otherVTagParameter = Parameters[2] 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);

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

            List <WPropertyExpression> edgeProperties         = new List <WPropertyExpression>();
            List <PropertyTuple>       subtraversalProperties = new List <PropertyTuple>();

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

            projectedField.Add(GremlinKeyword.Label);

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

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

                if (property.Value is WValueExpression)
                {
                    edgeProperties.Add(property);
                }
                else
                {
                    WScalarSubquery        scalarSubquery = property.Value as WScalarSubquery;
                    ScalarSubqueryFunction valueFunction  = (ScalarSubqueryFunction)scalarSubquery.CompileToFunction(context, command);
                    subtraversalProperties.Add(new PropertyTuple(property.Cardinality, property.Key.Value, valueFunction));
                }
            }

            JObject edgeJsonObject = ConstructEdgeJsonObject(command, labelValue.Value, edgeProperties);  // metadata remains missing

            GraphViewExecutionOperator addEOp = new AddEOperator(context.CurrentExecutionOperator, command, container,
                                                                 srcSubQueryOp, sinkSubQueryOp, otherVTag, edgeJsonObject, projectedField, subtraversalProperties);

            context.CurrentExecutionOperator = addEOp;

            // Update context's record layout
            context.AddField(Alias.Value, GremlinKeyword.EdgeSourceV, ColumnGraphType.EdgeSource);
            context.AddField(Alias.Value, GremlinKeyword.EdgeSinkV, ColumnGraphType.EdgeSink);
            context.AddField(Alias.Value, GremlinKeyword.EdgeOtherV, ColumnGraphType.Value);
            context.AddField(Alias.Value, GremlinKeyword.EdgeID, ColumnGraphType.EdgeId);
            context.AddField(Alias.Value, GremlinKeyword.Star, ColumnGraphType.EdgeObject);
            for (var i = GraphViewReservedProperties.ReservedEdgeProperties.Count; i < projectedField.Count; i++)
            {
                context.AddField(Alias.Value, projectedField[i], ColumnGraphType.Value);
            }

            return(addEOp);
        }