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