private void DropEdge(EdgeField edgeField)
        {
            RawRecord record = new RawRecord();

            record.Append(new StringField(edgeField.OutV));              // srcIdIndex
            record.Append(new StringField(edgeField.Offset.ToString())); // edgeOffsetIndex
            DropEdgeOperator op = new DropEdgeOperator(this.dummyInputOp, this.connection, 0, 1);

            op.DataModify(record);

            // Now VertexCacheObject has been updated (in DataModify)
        }
Пример #2
0
        internal override GraphViewExecutionOperator Compile(QueryCompilationContext context, GraphViewConnection dbConnection)
        {
            var srcIdParameter      = Parameters[0] as WColumnReferenceExpression;
            var edgeOffsetParameter = Parameters[1] as WColumnReferenceExpression;
            var srcIdIndex          = context.LocateColumnReference(srcIdParameter);
            var edgeOffsetIndex     = context.LocateColumnReference(edgeOffsetParameter);

            var dropEdgeOp = new DropEdgeOperator(context.CurrentExecutionOperator, dbConnection, srcIdIndex, edgeOffsetIndex);

            context.CurrentExecutionOperator = dropEdgeOp;

            return(dropEdgeOp);
        }
        // TODO: Batch upload for the DropEdge part
        internal override RawRecord DataModify(RawRecord record)
        {
            string vertexId = record[this._nodeIdIndex].ToValue;

            // Temporarily change
            DropEdgeOperator dropEdgeOp = new DropEdgeOperator(null, this.Connection, 0, 1);
            RawRecord        temp       = new RawRecord(2);

            VertexField vertex = this.Connection.VertexCache.GetVertexField(vertexId);

            // Save a copy of Edges _IDs & drop outgoing edges
            List <long> outEdgeOffsets = vertex.AdjacencyList.AllEdges.Select(e => e.Offset).ToList();

            foreach (long outEdgeOffset in outEdgeOffsets)
            {
                temp.fieldValues[0] = new StringField(vertexId);
                temp.fieldValues[1] = new StringField(outEdgeOffset.ToString());
                dropEdgeOp.DataModify(temp);
            }

            AdjacencyListField revAdjacencyListField = Connection.UseReverseEdges
                                                       ? vertex.RevAdjacencyList
                                                       : EdgeDocumentHelper.GetReverseAdjacencyListOfVertex(Connection, vertexId);
            // Save a copy of incoming Edges <srcVertexId, edgeOffsetInSrcVertex> & drop them
            List <Tuple <string, long> > inEdges = revAdjacencyListField.AllEdges.Select(
                e => new Tuple <string, long>(e.OutV, e.Offset)).ToList();

            foreach (var inEdge in inEdges)
            {
                temp.fieldValues[0] = new StringField(inEdge.Item1);            // srcVertexId
                temp.fieldValues[1] = new StringField(inEdge.Item2.ToString()); // edgeOffsetInSrcVertex
                dropEdgeOp.DataModify(temp);
            }

            // Delete the node-document!
#if DEBUG
            JObject vertexObject = this.Connection.RetrieveDocumentById(vertexId);
            Debug.Assert(vertexObject != null);
            Debug.Assert(vertexObject["_edge"] is JArray);
            Debug.Assert(((JArray)vertexObject["_edge"]).Count == 0);
            Debug.Assert(vertexObject["_reverse_edge"] is JArray);
            Debug.Assert(((JArray)vertexObject["_reverse_edge"]).Count == 0);
#endif
            // NOTE: for vertex document, id = _partition
            this.Connection.ReplaceOrDeleteDocumentAsync(vertexId, null, vertexId).Wait();

            // Update VertexCache
            this.Connection.VertexCache.TryRemoveVertexField(vertexId);

            return(null);
        }