public static string Serialize(GraphViewCommand command, Dictionary <string, IAggregateFunction> sideEffectFunctions, GraphViewExecutionOperator op) { string commandString = SerializeWithSoapFormatter(command); WrapSideEffectFunctions wrapSideEffectFunctions = new WrapSideEffectFunctions(sideEffectFunctions); string sideEffectString = SerializeWithSoapFormatter(wrapSideEffectFunctions); string opString = SerializeWithSoapFormatter(op); // To combine three string into one string. string[] arr = { commandString, sideEffectString, opString }; return(SerializeWithSoapFormatter(arr)); }
internal JObject RetrieveDocumentById(string docId, string partition, GraphViewCommand command) { Debug.Assert(!string.IsNullOrEmpty(docId), "'docId' should not be null or empty"); const string NODE_ALIAS = "doc"; JsonQuery jsonQuery = new JsonQuery { NodeAlias = NODE_ALIAS }; jsonQuery.AddSelectElement("*"); jsonQuery.RawWhereClause = new WBooleanComparisonExpression { ComparisonType = BooleanComparisonType.Equals, FirstExpr = new WColumnReferenceExpression(NODE_ALIAS, KW_DOC_ID), SecondExpr = new WValueExpression(docId, true) }; jsonQuery.FlatProperties.Add(KW_DOC_ID); if (partition != null) { Debug.Assert(this.PartitionPath != null); jsonQuery.FlatProperties.Add(partition); jsonQuery.WhereConjunction(new WBooleanComparisonExpression { ComparisonType = BooleanComparisonType.Equals, // TODO: new type to represent this?? FirstExpr = new WValueExpression($"{NODE_ALIAS}{this.GetPartitionPathIndexer()}", false), SecondExpr = new WValueExpression(partition, true) }, BooleanBinaryExpressionType.And); } JObject result = this.CreateDatabasePortal().GetVertexDocument(jsonQuery); // // Save etag of the fetched document // No override! // if (result != null) { command.VertexCache.SaveCurrentEtagNoOverride(result); } return(result); }
/// <summary> /// </summary> /// <param name="command"></param> /// <param name="edgeLabel"></param> /// <param name="edgeProperties">All propertyValue is WValueExpression!</param> /// <returns></returns> public JObject ConstructEdgeJsonObject(GraphViewCommand command, string edgeLabel, List <WPropertyExpression> edgeProperties) { JObject edgeObject = new JObject { [KW_EDGE_LABEL] = edgeLabel }; // Skip edgeSourceScalarFunction, edgeSinkScalarFunction, otherVTag foreach (WPropertyExpression edgeProperty in edgeProperties) { WValueExpression propertyValue = edgeProperty.Value as WValueExpression; GraphViewJsonCommand.UpdateProperty(edgeObject, edgeProperty.Key, propertyValue); } return(edgeObject); }
/// <summary> /// Try to upload one document. /// If the operation fails because document is too large, nothing is changed and "tooLarge" is set true. /// If the operation fails due to other reasons, nothing is changed and an exception is thrown /// If the operation succeeds, docObject[KW_DOC_ID] is set if it doesn't have one /// </summary> /// <param name="command"></param> /// <param name="docId"></param> /// <param name="docObject"></param> /// <param name="tooLarge"></param> private static void UploadOne(GraphViewCommand command, string docId, JObject docObject, bool isCreate, out bool tooLarge) { tooLarge = false; try { Debug.Assert(docObject != null); if (isCreate) { command.Connection.CreateDocumentAsync(docObject, command).Wait(); } else { command.Connection.ReplaceOrDeleteDocumentAsync(docId, docObject, command.Connection.GetDocumentPartition(docObject), command).Wait(); } } catch (AggregateException ex) when((ex.InnerException as DocumentClientException)?.Error.Code == "RequestEntityTooLarge") { tooLarge = true; } }
public void Upload(GraphViewCommand command) { if (this.isAddV && this.isDropV) { return; } if (this.isDropV) { command.Connection.ReplaceOrDeleteDocumentAsync(this.vertexField.VertexId, null, command.Connection.GetDocumentPartition(this.vertexField.VertexJObject), command).Wait(); } else if (this.isAddV) { command.Connection.CreateDocumentAsync(this.vertexField.VertexJObject, command).Wait(); } else if (this.deltaProperties.Count > 0) { command.Connection.ReplaceOrDeleteDocumentAsync(this.vertexField.VertexId, this.vertexField.VertexJObject, command.Connection.GetDocumentPartition(this.vertexField.VertexJObject), command).Wait(); } }
public static Tuple <GraphViewCommand, GraphViewExecutionOperator> Deserialize(string serializationString) { string[] arr = (string[])DeserializeWithSoapFormatter(serializationString); string commandString = arr[0]; GraphViewCommand command = (GraphViewCommand)DeserializeWithSoapFormatter(commandString); // Deserilization of sideEffectFunctions needs information about command. string sideEffectString = arr[1]; AdditionalSerializationInfo additionalInfo = new AdditionalSerializationInfo(command); WrapSideEffectFunctions wrapSideEffectFunctions = (WrapSideEffectFunctions)DeserializeWithSoapFormatter(sideEffectString, additionalInfo); // Deserilization of op needs information about command and sideEffectFunctions. string opString = arr[2]; additionalInfo.SideEffectFunctions = wrapSideEffectFunctions.sideEffectFunctions; GraphViewExecutionOperator op = (GraphViewExecutionOperator)DeserializeWithSoapFormatter(opString, additionalInfo); return(new Tuple <GraphViewCommand, GraphViewExecutionOperator>(command, op)); }
internal override ScalarFunction CompileToFunction(QueryCompilationContext context, GraphViewCommand command) { QueryCompilationContext subContext = new QueryCompilationContext(context); Container container = new Container(); subContext.OuterContextOp.SetContainer(container); GraphViewExecutionOperator subQueryOp = SubQueryExpr.Compile(subContext, command); return(new ScalarSubqueryFunction(subQueryOp, container)); }
public int ExecuteNonQuery(string queryString) { using (var command = new GraphViewCommand(queryString, this)) { return command.ExecuteNonQuery(); } }
internal override BooleanFunction CompileToFunction(QueryCompilationContext context, GraphViewCommand command) { return(new BooleanNotFunction(Expression.CompileToFunction(context, command))); }
internal override BooleanFunction CompileToFunction(QueryCompilationContext context, GraphViewCommand command) { ScalarFunction f1 = FirstExpr.CompileToFunction(context, command); ScalarFunction f2 = SecondExpr.CompileToFunction(context, command); return(new ComparisonFunction(f1, f2, ComparisonType)); }
internal override BooleanFunction CompileToBatchFunction(QueryCompilationContext context, GraphViewCommand command) { QueryCompilationContext subContext = new QueryCompilationContext(context); Container container = new Container(); subContext.OuterContextOp.SetContainer(container); subContext.AddField(GremlinKeyword.IndexTableName, command.IndexColumnName, ColumnGraphType.Value, true); subContext.InBatchMode = true; GraphViewExecutionOperator subQueryOp = this.Subquery.SubQueryExpr.Compile(subContext, command); ExistsFunction existsFunc = new ExistsFunction(subQueryOp, container); return(existsFunc); }
internal override BooleanFunction CompileToBatchFunction(QueryCompilationContext context, GraphViewCommand command) { return(this.Expression.CompileToBatchFunction(context, command)); }
internal override ScalarFunction CompileToFunction(QueryCompilationContext context, GraphViewCommand command) { DateTime date_value; double double_value; float float_value; long long_value; int int_value; bool bool_value; if (SingleQuoted) { if (DateTime.TryParse(Value, out date_value)) { return(new ScalarValue(Value, JsonDataType.Date)); } else { return(new ScalarValue(Value, JsonDataType.String)); } } else { if (Value.Equals("null", StringComparison.CurrentCultureIgnoreCase)) { return(new ScalarValue(Value, JsonDataType.Null)); } else if (bool.TryParse(Value, out bool_value)) { return(new ScalarValue(Value, JsonDataType.Boolean)); } else if (Value.IndexOf('.') >= 0) { if (float.TryParse(Value, out float_value)) { return(new ScalarValue(Value, JsonDataType.Float)); } else if (double.TryParse(Value, out double_value)) { return(new ScalarValue(Value, JsonDataType.Double)); } } else if (Value.StartsWith("0x")) { return(new ScalarValue(Value, JsonDataType.Bytes)); } else if (int.TryParse(Value, out int_value)) { return(new ScalarValue(Value, JsonDataType.Int)); } else if (long.TryParse(Value, out long_value)) { return(new ScalarValue(Value, JsonDataType.Long)); } throw new QueryCompilationException(string.Format("Failed to interpret string \"{0}\" into any data type.", Value)); } }
internal override ScalarFunction CompileToFunction(QueryCompilationContext context, GraphViewCommand command) { ScalarFunction f1 = FirstExpr.CompileToFunction(context, command); ScalarFunction f2 = SecondExpr.CompileToFunction(context, command); return(new BinaryScalarFunction(f1, f2, ExpressionType)); }
internal override GraphViewExecutionOperator Compile(QueryCompilationContext context, GraphViewCommand command) { CommitOperator commitOp = new CommitOperator(command, context.CurrentExecutionOperator); context.CurrentExecutionOperator = commitOp; return(commitOp); }
public void Upload(GraphViewCommand command) { if (this.isAddE && this.isDropE) { return; } else if (this.isAddE) { string outEdgeDocId; EdgeDocumentHelper.InsertEdgeObjectInternal(command, this.srcVertexField.VertexJObject, this.srcVertexField, this.outEdgeField.EdgeJObject, false, out outEdgeDocId); this.outEdgeField.EdgeDocID = outEdgeDocId; if (this.UseReverseEdges) { string inEdgeDocId; EdgeDocumentHelper.InsertEdgeObjectInternal(command, this.sinkVertexField.VertexJObject, this.sinkVertexField, this.inEdgeField.EdgeJObject, true, out inEdgeDocId); this.inEdgeField.EdgeDocID = inEdgeDocId; } } else if (this.isDropE) { string edgeId = outEdgeField.EdgeId; string srcId = outEdgeField.OutV; string sinkId = outEdgeField.InV; JObject outEdgeObject; string outEdgeDocId; EdgeDocumentHelper.FindEdgeBySourceAndEdgeId( command, this.srcVertexField.VertexJObject, srcId, edgeId, false, out outEdgeObject, out outEdgeDocId); if (outEdgeObject == null) { // something wrong. the edge that we want to drop does not exist in db return; } string inEdgeDocId = null; if (this.UseReverseEdges) { if (!string.Equals(sinkId, srcId)) { JObject dummySinkEdgeObject; EdgeDocumentHelper.FindEdgeBySourceAndEdgeId( command, this.sinkVertexField.VertexJObject, srcId, edgeId, true, out dummySinkEdgeObject, out inEdgeDocId); } else { Debug.Assert(object.ReferenceEquals(this.sinkVertexField, this.srcVertexField)); Debug.Assert(this.sinkVertexField.VertexJObject == this.srcVertexField.VertexJObject); inEdgeDocId = outEdgeDocId; } } // <docId, <docJson, partition>> Dictionary <string, Tuple <JObject, string> > uploadDocuments = new Dictionary <string, Tuple <JObject, string> >(); EdgeDocumentHelper.RemoveEdge(uploadDocuments, command, outEdgeDocId, this.srcVertexField, false, srcId, edgeId); if (this.UseReverseEdges) { EdgeDocumentHelper.RemoveEdge(uploadDocuments, command, inEdgeDocId, this.sinkVertexField, true, srcId, edgeId); } command.Connection.ReplaceOrDeleteDocumentsAsync(uploadDocuments, command).Wait(); } else if (this.deltaProperties.Count > 0) { string edgeId = outEdgeField.EdgeId; string srcId = outEdgeField.OutV; string sinkId = outEdgeField.InV; JObject outEdgeObject; string outEdgeDocId; EdgeDocumentHelper.FindEdgeBySourceAndEdgeId( command, this.srcVertexField.VertexJObject, srcId, edgeId, false, out outEdgeObject, out outEdgeDocId); if (outEdgeObject == null) { // something wrong. the edge that we want to update does not exist in db return; } string inEdgeDocId = null; if (this.UseReverseEdges) { if (!string.Equals(sinkId, srcId)) { JObject inEdgeObject; EdgeDocumentHelper.FindEdgeBySourceAndEdgeId( command, this.sinkVertexField.VertexJObject, srcId, edgeId, true, out inEdgeObject, out inEdgeDocId); } else { Debug.Assert(object.ReferenceEquals(this.sinkVertexField, this.srcVertexField)); Debug.Assert(this.sinkVertexField.VertexJObject == this.srcVertexField.VertexJObject); inEdgeDocId = outEdgeDocId; } } // Interact with DocDB to update the property EdgeDocumentHelper.UpdateEdgeProperty(command, this.srcVertexField.VertexJObject, outEdgeDocId, false, this.outEdgeField.EdgeJObject); if (this.UseReverseEdges) { EdgeDocumentHelper.UpdateEdgeProperty(command, this.sinkVertexField.VertexJObject, inEdgeDocId, true, this.inEdgeField.EdgeJObject); } } }
internal async Task ReplaceOrDeleteDocumentAsync(string docId, JObject docObject, string partition, GraphViewCommand command) { if (this.DocDBClient != null) { await((DocumentDbPortal)this.CreateDatabasePortal()).ReplaceOrDeleteDocumentAsync(docId, docObject, command, partition); } else { ((JsonServerDbPortal)this.CreateDatabasePortal()).ReplaceOrDeleteDocument(docId, docObject, command, partition); } }
internal async Task ReplaceOrDeleteDocumentsAsync(Dictionary <string, Tuple <JObject, string> > documentsMap, GraphViewCommand command) { #if DEBUG // Make sure that there aren't two docObject (not null) sharing the same reference List <Tuple <JObject, string> > docObjectList = documentsMap.Values.Where(tuple => tuple.Item1 != null).ToList(); HashSet <Tuple <JObject, string> > docObjectSet = new HashSet <Tuple <JObject, string> >(docObjectList); Debug.Assert(docObjectList.Count == docObjectSet.Count, "Replacing documents with two docObject sharing the same reference"); #endif foreach (KeyValuePair <string, Tuple <JObject, string> > pair in documentsMap) { string docId = pair.Key; JObject docObject = pair.Value.Item1; // Can be null (null means deletion) string partition = pair.Value.Item2; // Partition if (docObject != null) { Debug.Assert(partition == this.GetDocumentPartition(docObject)); } await this.ReplaceOrDeleteDocumentAsync(docId, docObject, partition, command); } }
internal override ScalarFunction CompileToFunction(QueryCompilationContext context, GraphViewCommand command) { int fieldIndex = context.LocateColumnReference(this); return(new FieldValue(fieldIndex)); }
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); }
internal virtual BooleanFunction CompileToFunction(QueryCompilationContext context, GraphViewCommand command) { return(null); }
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); }
internal override BooleanFunction CompileToFunction(QueryCompilationContext context, GraphViewCommand command) { QueryCompilationContext subContext = new QueryCompilationContext(context); Container container = new Container(); subContext.OuterContextOp.SetContainer(container); GraphViewExecutionOperator subQueryOp = Subquery.SubQueryExpr.Compile(subContext, command); ExistsFunction existsFunc = new ExistsFunction(subQueryOp, container); return(existsFunc); }
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); }
internal override BooleanFunction CompileToBatchFunction(QueryCompilationContext context, GraphViewCommand command) { BooleanFunction bf1 = this.FirstExpr.CompileToBatchFunction(context, command); BooleanFunction bf2 = this.SecondExpr.CompileToBatchFunction(context, command); if (this.BooleanExpressionType == BooleanBinaryExpressionType.And) { return(new BooleanBinaryFunction(bf1, bf2, BooleanBinaryFunctionType.And)); } else { return(new BooleanBinaryFunction(bf1, bf2, BooleanBinaryFunctionType.Or)); } }
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 BooleanFunction CompileToFunction(QueryCompilationContext context, GraphViewCommand command) { ScalarFunction lhsFunction; if (this.Expression != null) { lhsFunction = this.Expression.CompileToFunction(context, command); } else if (this.Subquery != null) { lhsFunction = this.Subquery.CompileToFunction(context, command); } else { throw new QueryCompilationException("Expression and Subquery can't all be null in a WInPredicate."); } List <ScalarFunction> values = this.Values.Select(value => value.CompileToFunction(context, command)).ToList(); return(new InFunction(lhsFunction, values, this.NotDefined)); }
internal virtual GraphViewExecutionOperator Compile(QueryCompilationContext context, GraphViewCommand command) { return(null); }
public SqlDataReader ExecuteReader(string queryString, int timeout = 0 ) { using (var command = new GraphViewCommand(queryString, this)) { command.CommandTimeOut = timeout; return command.ExecuteReader(); } }
internal virtual ScalarFunction CompileToFunction(QueryCompilationContext context, GraphViewCommand command) { throw new NotImplementedException(); }
public GraphViewExecutionOperator Compile(QueryCompilationContext context, GraphViewCommand command) { return(this.TableReference.Compile(context, command)); }
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."); }