public JObject ConstructNodeJsonDocument(out List <string> projectedFieldList) { JObject nodeJsonDocument = new JObject(); projectedFieldList = new List <string>(GraphViewReservedProperties.ReservedNodeProperties); for (var i = 0; i < Parameters.Count; i += 2) { var key = (Parameters[i] as WValueExpression).Value; //nodeJsonDocument = GraphViewJsonCommand.insert_property(nodeJsonDocument, value, key).ToString(); GraphViewJsonCommand.UpdateProperty(nodeJsonDocument, Parameters[i] as WValueExpression, Parameters[i + 1] as WValueExpression); if (!projectedFieldList.Contains(key)) { projectedFieldList.Add(key); } } //nodeJsonDocument = GraphViewJsonCommand.insert_property(nodeJsonDocument, "[]", "_edge").ToString(); //nodeJsonDocument = GraphViewJsonCommand.insert_property(nodeJsonDocument, "[]", "_reverse_edge").ToString(); nodeJsonDocument["_edge"] = new JArray(); nodeJsonDocument["_reverse_edge"] = new JArray(); nodeJsonDocument["_nextEdgeOffset"] = 0; return(nodeJsonDocument); }
/// <summary> /// Add an edge from one vertex (source) to another (sink) /// NOTE: Both the source and sink vertex are modified. /// NOTE: This function may upload the edge-document. /// NOTE: srcVertex and sinkVertex are updated and uploaded. /// </summary> /// <param name="connection"></param> /// <param name="srcId"></param> /// <param name="sinkId"></param> /// <param name="srcVertexField"></param> /// <param name="sinkVertexField"></param> /// <param name="edgeJsonObject"></param> /// <param name="srcVertexObject"></param> /// <param name="sinkVertexObject"></param> /// <param name="outEdgeObject"></param> /// <param name="outEdgeDocID"></param> /// <param name="inEdgeObject"></param> /// <param name="inEdgeDocID"></param> public static void InsertEdgeAndUpload( GraphViewConnection connection, string srcId, string sinkId, VertexField srcVertexField, VertexField sinkVertexField, JObject edgeJsonObject, JObject srcVertexObject, JObject sinkVertexObject, out JObject outEdgeObject, out string outEdgeDocID, out JObject inEdgeObject, out string inEdgeDocID) { long edgeOffset = (long)srcVertexObject["_nextEdgeOffset"]; srcVertexObject["_nextEdgeOffset"] = edgeOffset + 1; outEdgeObject = (JObject)edgeJsonObject.DeepClone(); inEdgeObject = (JObject)edgeJsonObject.DeepClone(); // Add "id" property to edgeObject if desired if (connection.GenerateEdgeId) { string guid = GraphViewConnection.GenerateDocumentId(); outEdgeObject["_edgeId"] = guid; inEdgeObject["_edgeId"] = guid; } string srcLabel = srcVertexObject["label"]?.ToString(); string sinkLabel = sinkVertexObject["label"]?.ToString(); GraphViewJsonCommand.UpdateEdgeMetaProperty(outEdgeObject, edgeOffset, false, sinkId, sinkLabel); GraphViewJsonCommand.UpdateEdgeMetaProperty(inEdgeObject, edgeOffset, true, srcId, srcLabel); InsertEdgeObjectInternal(connection, srcVertexObject, srcVertexField, outEdgeObject, false, out outEdgeDocID); // srcVertex uploaded InsertEdgeObjectInternal(connection, sinkVertexObject, sinkVertexField, inEdgeObject, true, out inEdgeDocID); // sinkVertex uploaded }
public JObject ConstructEdgeJsonObject(WValueExpression edgeLabel, List <WPropertyExpression> addedProperties) { JObject edgeJsonDocument = new JObject(); GraphViewJsonCommand.UpdateProperty(edgeJsonDocument, SqlUtil.GetValueExpr(GremlinKeyword.Label), edgeLabel); foreach (WPropertyExpression property in addedProperties) { GraphViewJsonCommand.UpdateProperty(edgeJsonDocument, property.Key, property.Value); } return(edgeJsonDocument); }
private void UpdateNodeProperties( Dictionary <string, JObject> documentsMap, string vertexId, JObject vertexDocObject, List <Tuple <WValueExpression, WValueExpression, int> > propList, UpdatePropertyMode mode) { VertexField vertexField = this.Connection.VertexCache.GetVertexField(vertexId); // Drop all non-reserved properties if (propList.Count == 1 && !propList[0].Item1.SingleQuoted && propList[0].Item1.Value.Equals("*", StringComparison.OrdinalIgnoreCase) && !propList[0].Item2.SingleQuoted && propList[0].Item2.Value.Equals("null", StringComparison.OrdinalIgnoreCase)) { List <string> toBeDroppedPropertiesNames = GraphViewJsonCommand.DropAllNodeProperties(vertexDocObject); foreach (var propertyName in toBeDroppedPropertiesNames) { vertexField.VertexProperties.Remove(propertyName); } } else { foreach (var t in propList) { WValueExpression keyExpression = t.Item1; WValueExpression valueExpression = t.Item2; if (mode == UpdatePropertyMode.Set) { JProperty updatedProperty = GraphViewJsonCommand.UpdateProperty(vertexDocObject, keyExpression, valueExpression); if (updatedProperty == null) { vertexField.VertexProperties.Remove(keyExpression.Value); } else { vertexField.UpdateVertexProperty(updatedProperty.Name, updatedProperty.Value.ToString(), JsonDataTypeHelper.GetJsonDataType(updatedProperty.Value.Type)); } } else { throw new NotImplementedException(); } } } documentsMap[vertexId] = vertexDocObject; }
public JObject ConstructNodeJsonDocument(out List <string> projectedFieldList) { JObject nodeJsonDocument = new JObject(); projectedFieldList = new List <string>(GraphViewReservedProperties.ReservedNodeProperties); for (var i = 0; i < Parameters.Count; i += 2) { var key = (Parameters[i] as WValueExpression).Value; //GraphViewJsonCommand.UpdateProperty(nodeJsonDocument, Parameters[i] as WValueExpression, // Parameters[i + 1] as WValueExpression); GraphViewJsonCommand.UpdateProperty(nodeJsonDocument, Parameters[i] as WValueExpression, Parameters[i + 1] as WValueExpression); string name = (Parameters[i] as WValueExpression).Value; JToken value = (Parameters[i + 1] as WValueExpression).ToJValue(); if (value != null) { if (VertexField.IsVertexMetaProperty(name)) { nodeJsonDocument[name] = value; } else { nodeJsonDocument[name] = new JArray { new JObject { ["_value"] = value, ["_propId"] = GraphViewConnection.GenerateDocumentId(), ["_meta"] = new JObject(), }, }; } } if (!projectedFieldList.Contains(key)) { projectedFieldList.Add(key); } } //nodeJsonDocument = GraphViewJsonCommand.insert_property(nodeJsonDocument, "[]", "_edge").ToString(); //nodeJsonDocument = GraphViewJsonCommand.insert_property(nodeJsonDocument, "[]", "_reverse_edge").ToString(); nodeJsonDocument["_edge"] = new JArray(); nodeJsonDocument["_reverse_edge"] = new JArray(); nodeJsonDocument["_nextEdgeOffset"] = 0; return(nodeJsonDocument); }
/// <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); }
public static string ConstructNodeJsonString(string nodeInfo) { string json_str = "{}"; char delimiter = '\t'; var properties_values = nodeInfo.Split(delimiter); for (int i = 0; i < properties_values.Length - 1; i += 2) { string property = properties_values[i]; string value = properties_values[i + 1]; json_str = GraphViewJsonCommand.insert_property(json_str, value, property).ToString(); } //Insert "_edge" & "_reverse_edge" into the string. json_str = GraphViewJsonCommand.insert_property(json_str, "[]", "_edge").ToString(); json_str = GraphViewJsonCommand.insert_property(json_str, "[]", "_reverse_edge").ToString(); return(json_str); }
public JObject ConstructEdgeJsonObject(out List <string> projectedFieldList) { projectedFieldList = new List <string>(GraphViewReservedProperties.ReservedEdgeProperties); JObject edgeJsonDocument = new JObject(); // Skip edgeSourceScalarFunction, edgeSinkScalarFunction, otherVTag for (var i = 3; i < Parameters.Count; i += 2) { var key = (Parameters[i] as WValueExpression).Value; //var value = (Parameters[i + 1] as WValueExpression).ToString(); //edgeJsonDocument = GraphViewJsonCommand.insert_property(edgeJsonDocument, value, key).ToString(); GraphViewJsonCommand.UpdateProperty(edgeJsonDocument, Parameters[i] as WValueExpression, Parameters[i + 1] as WValueExpression); if (!projectedFieldList.Contains(key)) { projectedFieldList.Add(key); } } return(edgeJsonDocument); }
/// <summary> /// Construct a Json's string which contains all the information about the new node. /// </summary> /// <returns></returns> public string ConstructNode() { string Json_str = "{}"; var cnt = InsertSource as WValuesInsertSource; for (int i = 0; i < Columns.Count(); i++) { string s1 = Columns[i].MultiPartIdentifier.Identifiers[0].Value; var cnt2 = (cnt.RowValues[0].ColumnValues[i] as WValueExpression); string s2 = cnt2.Value; if (cnt2.SingleQuoted) { s2 = '\"' + s2 + '\"'; } Json_str = GraphViewJsonCommand.insert_property(Json_str, s2, s1).ToString(); } //Insert "_edge" & "_reverse_edge" into the string. Json_str = GraphViewJsonCommand.insert_property(Json_str, "[]", "_edge").ToString(); Json_str = GraphViewJsonCommand.insert_property(Json_str, "[]", "_reverse_edge").ToString(); return(Json_str); }
/// <summary> /// Add an edge from one vertex (source) to another (sink) /// NOTE: Both the source and sink vertex are modified. /// NOTE: This function may upload the edge-document. /// NOTE: srcVertex and sinkVertex are updated and uploaded. /// </summary> /// <param name="connection"></param> /// <param name="srcId"></param> /// <param name="sinkId"></param> /// <param name="srcVertexField"></param> /// <param name="sinkVertexField"></param> /// <param name="edgeJsonObject"></param> /// <param name="srcVertexObject"></param> /// <param name="sinkVertexObject"></param> /// <param name="outEdgeObject"></param> /// <param name="outEdgeDocID"></param> /// <param name="inEdgeObject"></param> /// <param name="inEdgeDocID"></param> public static void InsertEdgeAndUpload( GraphViewConnection connection, string srcId, string sinkId, VertexField srcVertexField, VertexField sinkVertexField, JObject edgeJsonObject, JObject srcVertexObject, JObject sinkVertexObject, out JObject outEdgeObject, out string outEdgeDocID, out JObject inEdgeObject, out string inEdgeDocID) { //long edgeOffset = (long)srcVertexObject[KW_VERTEX_NEXTOFFSET]; //srcVertexObject[KW_VERTEX_NEXTOFFSET] = edgeOffset + 1; outEdgeObject = (JObject)edgeJsonObject.DeepClone(); inEdgeObject = (JObject)edgeJsonObject.DeepClone(); // Add "id" property to edgeObject string edgeId = GraphViewConnection.GenerateDocumentId(); string srcLabel = srcVertexObject[KW_VERTEX_LABEL]?.ToString(); string sinkLabel = sinkVertexObject[KW_VERTEX_LABEL]?.ToString(); GraphViewJsonCommand.UpdateEdgeMetaProperty(outEdgeObject, edgeId, false, sinkId, sinkLabel); GraphViewJsonCommand.UpdateEdgeMetaProperty(inEdgeObject, edgeId, true, srcId, srcLabel); InsertEdgeObjectInternal(connection, srcVertexObject, srcVertexField, outEdgeObject, false, out outEdgeDocID); // srcVertex uploaded if (connection.UseReverseEdges) { InsertEdgeObjectInternal(connection, sinkVertexObject, sinkVertexField, inEdgeObject, true, out inEdgeDocID); // sinkVertex uploaded } else { inEdgeDocID = EdgeDocumentHelper.VirtualReverseEdgeDocId; } }
internal override RawRecord DataModify(RawRecord record) { long edgeOffset = long.Parse(record[this._edgeOffsetIndex].ToValue); string srcVertexId = record[this._srcVertexIdIndex].ToValue; JObject srcVertexObject = this.Connection.RetrieveDocumentById(srcVertexId); string outEdgeDocId; JObject outEdgeObject; EdgeDocumentHelper.FindEdgeBySourceAndOffset( this.Connection, srcVertexObject, srcVertexId, edgeOffset, false, out outEdgeObject, out outEdgeDocId); if (outEdgeObject == null) { // TODO: Is there something wrong? Debug.WriteLine($"[UpdateEdgePropertiesOperator] The edge does not exist: vertexId = {srcVertexId}, edgeOffset = {edgeOffset}"); return(null); } string sinkVertexId = (string)outEdgeObject["_sinkV"]; JObject sinkVertexObject; string inEdgeDocId; JObject inEdgeObject; if (sinkVertexId.Equals(srcVertexId)) { sinkVertexObject = srcVertexObject; // NOTE: Must not use DeepClone() here! } else { sinkVertexObject = this.Connection.RetrieveDocumentById(sinkVertexId); } EdgeDocumentHelper.FindEdgeBySourceAndOffset( this.Connection, sinkVertexObject, srcVertexId, edgeOffset, true, out inEdgeObject, out inEdgeDocId); VertexField srcVertexField = this.Connection.VertexCache.GetVertexField(srcVertexId); VertexField sinkVertexField = this.Connection.VertexCache.GetVertexField(sinkVertexId); EdgeField outEdgeField = srcVertexField.AdjacencyList.GetEdgeField(srcVertexId, edgeOffset); EdgeField inEdgeField = sinkVertexField.RevAdjacencyList.GetEdgeField(srcVertexId, edgeOffset); // Drop all non-reserved properties if (this.PropertiesToBeUpdated.Count == 1 && !this.PropertiesToBeUpdated[0].Item1.SingleQuoted && this.PropertiesToBeUpdated[0].Item1.Value.Equals("*", StringComparison.OrdinalIgnoreCase) && !this.PropertiesToBeUpdated[0].Item2.SingleQuoted && this.PropertiesToBeUpdated[0].Item2.Value.Equals("null", StringComparison.OrdinalIgnoreCase)) { List <string> toBeDroppedProperties = GraphViewJsonCommand.DropAllEdgeProperties(outEdgeObject); foreach (var propertyName in toBeDroppedProperties) { outEdgeField.EdgeProperties.Remove(propertyName); } toBeDroppedProperties = GraphViewJsonCommand.DropAllEdgeProperties(inEdgeObject); foreach (var propertyName in toBeDroppedProperties) { inEdgeField.EdgeProperties.Remove(propertyName); } } else { foreach (Tuple <WValueExpression, WValueExpression, int> tuple in this.PropertiesToBeUpdated) { WValueExpression keyExpression = tuple.Item1; WValueExpression valueExpression = tuple.Item2; if (this.Mode == UpdatePropertyMode.Set) { // Modify edgeObject (update the edge property) JProperty updatedProperty = GraphViewJsonCommand.UpdateProperty(outEdgeObject, keyExpression, valueExpression); // Update VertexCache if (updatedProperty == null) { outEdgeField.EdgeProperties.Remove(keyExpression.Value); } else { outEdgeField.UpdateEdgeProperty(updatedProperty, outEdgeField); } // Modify edgeObject (update the edge property) updatedProperty = GraphViewJsonCommand.UpdateProperty(inEdgeObject, keyExpression, valueExpression); // Update VertexCache if (updatedProperty == null) { inEdgeField.EdgeProperties.Remove(keyExpression.Value); } else { inEdgeField.UpdateEdgeProperty(updatedProperty, inEdgeField); } } else { throw new NotImplementedException(); } } } // Interact with DocDB to update the property EdgeDocumentHelper.UpdateEdgeProperty(this.Connection, srcVertexObject, outEdgeDocId, false, outEdgeObject); EdgeDocumentHelper.UpdateEdgeProperty(this.Connection, sinkVertexObject, inEdgeDocId, true, inEdgeObject); // // Drop edge property // if (this.PropertiesToBeUpdated.Any(t => t.Item2 == null)) { return(null); } return(record); }