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); }
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); }