Search in sources :

Example 11 with EdgeId

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

the class GraphTransaction method queryEdgesByIds.

protected Iterator<Edge> queryEdgesByIds(Object[] edgeIds, boolean verifyId) {
    Query.checkForceCapacity(edgeIds.length);
    // NOTE: allowed duplicated edges if query by duplicated ids
    List<Id> ids = InsertionOrderUtil.newList();
    Map<Id, HugeEdge> edges = new HashMap<>(edgeIds.length);
    IdQuery query = new IdQuery(HugeType.EDGE);
    for (Object edgeId : edgeIds) {
        HugeEdge edge;
        EdgeId id = HugeEdge.getIdValue(edgeId, !verifyId);
        if (id == null) {
            continue;
        }
        if (id.direction() == Directions.IN) {
            id = id.switchDirection();
        }
        if (this.removedEdges.containsKey(id)) {
            // The record has been deleted
            continue;
        } else if ((edge = this.addedEdges.get(id)) != null || (edge = this.updatedEdges.get(id)) != null) {
            if (edge.expired()) {
                continue;
            }
            // Found from local tx
            edges.put(edge.id(), edge);
        } else {
            // Prepare to query from backend store
            query.query(id);
        }
        ids.add(id);
    }
    if (!query.empty()) {
        // Query from backend store
        if (edges.isEmpty() && query.idsSize() == ids.size()) {
            /*
                 * Sort at the lower layer and return directly if there is no
                 * local vertex and duplicated id.
                 */
            Iterator<HugeEdge> it = this.queryEdgesFromBackend(query);
            @SuppressWarnings({ "unchecked", "rawtypes" }) Iterator<Edge> r = (Iterator) it;
            return r;
        }
        query.mustSortByInput(false);
        Iterator<HugeEdge> it = this.queryEdgesFromBackend(query);
        QueryResults.fillMap(it, edges);
    }
    return new MapperIterator<>(ids.iterator(), id -> {
        Edge edge = edges.get(id);
        return edge;
    });
}
Also used : MapperIterator(com.baidu.hugegraph.iterator.MapperIterator) FlatMapperIterator(com.baidu.hugegraph.iterator.FlatMapperIterator) BatchMapperIterator(com.baidu.hugegraph.iterator.BatchMapperIterator) HashMap(java.util.HashMap) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) ListIterator(com.baidu.hugegraph.iterator.ListIterator) MapperIterator(com.baidu.hugegraph.iterator.MapperIterator) ExtendableIterator(com.baidu.hugegraph.iterator.ExtendableIterator) FlatMapperIterator(com.baidu.hugegraph.iterator.FlatMapperIterator) LimitIterator(com.baidu.hugegraph.iterator.LimitIterator) CloseableIterator(org.apache.tinkerpop.gremlin.structure.util.CloseableIterator) BatchMapperIterator(com.baidu.hugegraph.iterator.BatchMapperIterator) FilterIterator(com.baidu.hugegraph.iterator.FilterIterator) Iterator(java.util.Iterator) IdQuery(com.baidu.hugegraph.backend.query.IdQuery) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Example 12 with EdgeId

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

the class HugeEdge method assignId.

@Watched(prefix = "edge")
public void assignId() {
    // Generate an id and assign
    this.id = new EdgeId(this.ownerVertex(), this.direction(), this.schemaLabel().id(), this.name(), this.otherVertex());
    if (this.fresh()) {
        int len = this.id.length();
        E.checkArgument(len <= BytesBuffer.BIG_ID_LEN_MAX, "The max length of edge id is %s, but got %s {%s}", BytesBuffer.BIG_ID_LEN_MAX, len, this.id);
    }
}
Also used : EdgeId(com.baidu.hugegraph.backend.id.EdgeId) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 13 with EdgeId

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

the class JsonUtilTest method testSerializeEdgeId.

@Test
public void testSerializeEdgeId() {
    Id id = new EdgeId(IdGenerator.of("1:marko"), Directions.OUT, IdGenerator.of(1), "", IdGenerator.of("1:josh"));
    String json = JsonUtil.toJson(id);
    Assert.assertEquals("\"S1:marko>1>>S1:josh\"", json);
}
Also used : EdgeId(com.baidu.hugegraph.backend.id.EdgeId) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) Id(com.baidu.hugegraph.backend.id.Id) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 14 with EdgeId

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

the class EdgeIdTest method testCollectionContainsEdgeIdWithDirection.

@Test
public void testCollectionContainsEdgeIdWithDirection() {
    EdgeId edgeId1 = new EdgeId(IdGenerator.of("1:marko"), Directions.OUT, IdGenerator.of(1), "", IdGenerator.of("1:josh"), true);
    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"), true);
    Assert.assertTrue(edgeIds.contains(edgeId2));
    EdgeId edgeId3 = new EdgeId(IdGenerator.of("1:josh"), Directions.IN, IdGenerator.of(1), "", IdGenerator.of("1:marko"), true);
    Assert.assertFalse(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