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