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