Search in sources :

Example 1 with EdgeId

use of com.baidu.hugegraph.backend.id.EdgeId in project incubator-hugegraph by apache.

the class BinarySerializer method readVertex.

@Override
public HugeVertex readVertex(HugeGraph graph, BackendEntry bytesEntry) {
    if (bytesEntry == null) {
        return null;
    }
    BinaryBackendEntry entry = this.convertEntry(bytesEntry);
    // Parse id
    Id id = entry.id().origin();
    Id vid = id.edge() ? ((EdgeId) id).ownerVertexId() : id;
    HugeVertex vertex = new HugeVertex(graph, vid, VertexLabel.NONE);
    // Parse all properties and edges of a Vertex
    Iterator<BackendColumn> iterator = entry.columns().iterator();
    for (int index = 0; iterator.hasNext(); index++) {
        BackendColumn col = iterator.next();
        if (entry.type().isEdge()) {
            // NOTE: the entry id type is vertex even if entry type is edge
            // Parse vertex edges
            this.parseColumn(col, vertex);
        } else {
            assert entry.type().isVertex();
            // Parse vertex properties
            assert entry.columnsSize() >= 1 : entry.columnsSize();
            if (index == 0) {
                this.parseVertex(col.value, vertex);
            } else {
                this.parseVertexOlap(col.value, vertex);
            }
        }
    }
    return vertex;
}
Also used : BackendColumn(com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn) BinaryId(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Example 2 with EdgeId

use of com.baidu.hugegraph.backend.id.EdgeId in project incubator-hugegraph by apache.

the class BinarySerializer method writeEdgeId.

private BinaryId writeEdgeId(Id id) {
    EdgeId edgeId;
    if (id instanceof EdgeId) {
        edgeId = (EdgeId) id;
    } else {
        edgeId = EdgeId.parse(id.asString());
    }
    BytesBuffer buffer = BytesBuffer.allocate(BytesBuffer.BUF_EDGE_ID);
    if (this.enablePartition) {
        buffer.writeShort(getPartition(HugeType.EDGE, edgeId.ownerVertexId()));
        buffer.writeEdgeId(edgeId);
    } else {
        buffer.writeEdgeId(edgeId);
    }
    return new BinaryId(buffer.bytes(), id);
}
Also used : BinaryId(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId) EdgeId(com.baidu.hugegraph.backend.id.EdgeId)

Example 3 with EdgeId

use of com.baidu.hugegraph.backend.id.EdgeId in project incubator-hugegraph by apache.

the class EdgeAPI method getEdgeId.

private Id getEdgeId(HugeGraph g, JsonEdge newEdge) {
    String sortKeys = "";
    Id labelId = g.edgeLabel(newEdge.label).id();
    List<Id> sortKeyIds = g.edgeLabel(labelId).sortKeys();
    if (!sortKeyIds.isEmpty()) {
        List<Object> sortKeyValues = new ArrayList<>(sortKeyIds.size());
        sortKeyIds.forEach(skId -> {
            PropertyKey pk = g.propertyKey(skId);
            String sortKey = pk.name();
            Object sortKeyValue = newEdge.properties.get(sortKey);
            E.checkArgument(sortKeyValue != null, "The value of sort key '%s' can't be null", sortKey);
            sortKeyValue = pk.validValueOrThrow(sortKeyValue);
            sortKeyValues.add(sortKeyValue);
        });
        sortKeys = ConditionQuery.concatValues(sortKeyValues);
    }
    EdgeId edgeId = new EdgeId(HugeVertex.getIdValue(newEdge.source), Directions.OUT, labelId, sortKeys, HugeVertex.getIdValue(newEdge.target));
    if (newEdge.id != null) {
        E.checkArgument(edgeId.asString().equals(newEdge.id), "The ids are different between server and " + "request body ('%s' != '%s'). And note the sort " + "key values should either be null or equal to " + "the origin value when specified edge id", edgeId, newEdge.id);
    }
    return edgeId;
}
Also used : EdgeId(com.baidu.hugegraph.backend.id.EdgeId) ArrayList(java.util.ArrayList) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 4 with EdgeId

use of com.baidu.hugegraph.backend.id.EdgeId in project incubator-hugegraph by apache.

the class EdgeIdTest method testEdgeIdEqualWithDirection.

@Test
public void testEdgeIdEqualWithDirection() {
    EdgeId edgeId1 = new EdgeId(IdGenerator.of("1:marko"), Directions.OUT, IdGenerator.of(1), "", IdGenerator.of("1:josh"), true);
    EdgeId edgeId2 = new EdgeId(IdGenerator.of("1:marko"), Directions.OUT, IdGenerator.of(1), "", IdGenerator.of("1:josh"), true);
    EdgeId edgeId3 = new EdgeId(IdGenerator.of("1:josh"), Directions.IN, IdGenerator.of(1), "", IdGenerator.of("1:marko"), true);
    Assert.assertTrue(edgeId1.equals(edgeId2));
    Assert.assertTrue(edgeId2.equals(edgeId1));
    Assert.assertFalse(edgeId1.equals(edgeId3));
    Assert.assertFalse(edgeId3.equals(edgeId1));
}
Also used : EdgeId(com.baidu.hugegraph.backend.id.EdgeId) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 5 with EdgeId

use of com.baidu.hugegraph.backend.id.EdgeId in project incubator-hugegraph by apache.

the class EdgeIdTest method testCollectionContainsEdgeId.

@Test
public void testCollectionContainsEdgeId() {
    EdgeId edgeId1 = new EdgeId(IdGenerator.of("1:marko"), Directions.OUT, IdGenerator.of(1), "", IdGenerator.of("1:josh"));
    Set<Id> edgeIds = ImmutableSet.of(edgeId1);
    Assert.assertTrue(edgeIds.contains(edgeId1));
    EdgeId edgeId2 = new EdgeId(IdGenerator.of("1:marko"), Directions.OUT, IdGenerator.of(1), "", IdGenerator.of("1:josh"));
    Assert.assertTrue(edgeIds.contains(edgeId2));
    EdgeId edgeId3 = new EdgeId(IdGenerator.of("1:josh"), Directions.IN, IdGenerator.of(1), "", IdGenerator.of("1:marko"));
    Assert.assertTrue(edgeIds.contains(edgeId3));
}
Also used : EdgeId(com.baidu.hugegraph.backend.id.EdgeId) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Aggregations

EdgeId (com.baidu.hugegraph.backend.id.EdgeId)14 Id (com.baidu.hugegraph.backend.id.Id)6 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)5 Test (org.junit.Test)5 BinaryId (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId)2 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)2 ArrayList (java.util.ArrayList)2 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)1 BackendColumn (com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn)1 BatchMapperIterator (com.baidu.hugegraph.iterator.BatchMapperIterator)1 ExtendableIterator (com.baidu.hugegraph.iterator.ExtendableIterator)1 FilterIterator (com.baidu.hugegraph.iterator.FilterIterator)1 FlatMapperIterator (com.baidu.hugegraph.iterator.FlatMapperIterator)1 LimitIterator (com.baidu.hugegraph.iterator.LimitIterator)1 ListIterator (com.baidu.hugegraph.iterator.ListIterator)1 MapperIterator (com.baidu.hugegraph.iterator.MapperIterator)1 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)1 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)1 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)1 HashMap (java.util.HashMap)1