Search in sources :

Example 31 with HugeEdge

use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.

the class BinarySerializer method parseEdge.

protected void parseEdge(BackendColumn col, HugeVertex vertex, HugeGraph graph) {
    // owner-vertex + dir + edge-label + sort-values + other-vertex
    BytesBuffer buffer = BytesBuffer.wrap(col.name);
    if (this.keyWithIdPrefix) {
        // Consume owner-vertex id
        buffer.readId();
    }
    byte type = buffer.read();
    Id labelId = buffer.readId();
    String sortValues = buffer.readStringWithEnding();
    Id otherVertexId = buffer.readId();
    boolean direction = EdgeId.isOutDirectionFromCode(type);
    EdgeLabel edgeLabel = graph.edgeLabelOrNone(labelId);
    // Construct edge
    HugeEdge edge = HugeEdge.constructEdge(vertex, direction, edgeLabel, sortValues, otherVertexId);
    // Parse edge-id + edge-properties
    buffer = BytesBuffer.wrap(col.value);
    // Id id = buffer.readId();
    // Parse edge properties
    this.parseProperties(buffer, edge);
    // Parse edge expired time if needed
    if (edge.hasTtl()) {
        this.parseExpiredTime(buffer, edge);
    }
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) BinaryId(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId)

Example 32 with HugeEdge

use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.

the class GraphTransaction method removeEdgeProperty.

@Watched(prefix = "graph")
public <V> void removeEdgeProperty(HugeEdgeProperty<V> prop) {
    HugeEdge edge = prop.element();
    PropertyKey propKey = prop.propertyKey();
    E.checkState(edge != null, "No owner for removing property '%s'", prop.key());
    // Maybe have ever been removed
    if (!edge.hasProperty(propKey.id())) {
        return;
    }
    // Check is removing sort key
    List<Id> sortKeyIds = edge.schemaLabel().sortKeys();
    E.checkArgument(!sortKeyIds.contains(prop.propertyKey().id()), "Can't remove sort key '%s'", prop.key());
    // Remove property in memory for new created edge
    if (edge.fresh()) {
        // The owner will do property update
        edge.removeProperty(propKey.id());
        return;
    }
    // Check is updating property of added/removed edge
    E.checkArgument(!this.addedEdges.containsKey(edge.id()) || this.updatedEdges.containsKey(edge.id()), "Can't remove property '%s' for adding-state edge", prop.key());
    E.checkArgument(!this.removedEdges.containsKey(edge.id()), "Can't remove property '%s' for removing-state edge", prop.key());
    // Do property update
    this.lockForUpdateProperty(edge.schemaLabel(), prop, () -> {
        // Update old edge to remove index (with the property)
        this.indexTx.updateEdgeIndex(edge, true);
        // Update(remove) edge property
        this.propertyUpdated(edge, null, edge.removeProperty(propKey.id()));
    });
}
Also used : HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 33 with HugeEdge

use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.

the class GraphTransaction method prepareDeletions.

protected void prepareDeletions(Map<Id, HugeEdge> removedEdges) {
    // Remove edges
    for (HugeEdge e : removedEdges.values()) {
        this.checkAggregateProperty(e);
        // Update edge index
        this.indexTx.updateEdgeIndex(e, true);
        this.indexTx.updateLabelIndex(e, true);
        // Remove edge of OUT and IN
        e = e.prepareRemoved();
        this.doRemove(this.serializer.writeEdge(e));
        this.doRemove(this.serializer.writeEdge(e.switchOwner()));
    }
}
Also used : HugeEdge(com.baidu.hugegraph.structure.HugeEdge)

Example 34 with HugeEdge

use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.

the class GraphTransaction method prepareAdditions.

protected void prepareAdditions(Map<Id, HugeVertex> addedVertices, Map<Id, HugeEdge> addedEdges) {
    if (this.checkCustomVertexExist) {
        this.checkVertexExistIfCustomizedId(addedVertices);
    }
    if (this.removeLeftIndexOnOverwrite) {
        this.removeLeftIndexIfNeeded(addedVertices);
    }
    // Do vertex update
    for (HugeVertex v : addedVertices.values()) {
        assert !v.removed();
        v.committed();
        this.checkAggregateProperty(v);
        // Check whether passed all non-null properties
        if (!this.graphMode().loading()) {
            this.checkNonnullProperty(v);
        }
        // Add vertex entry
        this.doInsert(this.serializer.writeVertex(v));
        // Update index of vertex(only include props)
        this.indexTx.updateVertexIndex(v, false);
        this.indexTx.updateLabelIndex(v, false);
    }
    // Do edge update
    for (HugeEdge e : addedEdges.values()) {
        assert !e.removed();
        e.committed();
        // Skip edge if its owner has been removed
        if (this.removingEdgeOwner(e)) {
            continue;
        }
        this.checkAggregateProperty(e);
        // Add edge entry of OUT and IN
        this.doInsert(this.serializer.writeEdge(e));
        this.doInsert(this.serializer.writeEdge(e.switchOwner()));
        // Update index of edge
        this.indexTx.updateEdgeIndex(e, false);
        this.indexTx.updateLabelIndex(e, false);
    }
}
Also used : HugeEdge(com.baidu.hugegraph.structure.HugeEdge) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Example 35 with HugeEdge

use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.

the class GraphTransaction method addEdgeProperty.

@Watched(prefix = "graph")
public <V> void addEdgeProperty(HugeEdgeProperty<V> prop) {
    // NOTE: this method can also be used to update property
    HugeEdge edge = prop.element();
    E.checkState(edge != null, "No owner for updating property '%s'", prop.key());
    // Add property in memory for new created edge
    if (edge.fresh()) {
        // The owner will do property update
        edge.setProperty(prop);
        return;
    }
    // Check is updating property of added/removed edge
    E.checkArgument(!this.addedEdges.containsKey(edge.id()) || this.updatedEdges.containsKey(edge.id()), "Can't update property '%s' for adding-state edge", prop.key());
    E.checkArgument(!edge.removed() && !this.removedEdges.containsKey(edge.id()), "Can't update property '%s' for removing-state edge", prop.key());
    // Check is updating sort key
    List<Id> sortKeys = edge.schemaLabel().sortKeys();
    E.checkArgument(!sortKeys.contains(prop.propertyKey().id()), "Can't update sort key '%s'", prop.key());
    // Do property update
    this.lockForUpdateProperty(edge.schemaLabel(), prop, () -> {
        // Update old edge to remove index (without new property)
        this.indexTx.updateEdgeIndex(edge, true);
        // Update(add) edge property
        this.propertyUpdated(edge, prop, edge.setProperty(prop));
    });
}
Also used : HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Aggregations

HugeEdge (com.baidu.hugegraph.structure.HugeEdge)54 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)29 Id (com.baidu.hugegraph.backend.id.Id)26 Edge (org.apache.tinkerpop.gremlin.structure.Edge)22 Test (org.junit.Test)20 HugeGraph (com.baidu.hugegraph.HugeGraph)17 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)12 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)11 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)9 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)9 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)8 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)8 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)6 EdgeStep (com.baidu.hugegraph.traversal.algorithm.steps.EdgeStep)6 Iterator (java.util.Iterator)6 List (java.util.List)6 Set (java.util.Set)6 HugeException (com.baidu.hugegraph.HugeException)5 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)5 HugeConfig (com.baidu.hugegraph.config.HugeConfig)5