use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.
the class FakeObjects method newEdge.
public HugeEdge newEdge(long sourceVertexId, long targetVertexId) {
PropertyKey name = this.newPropertyKey(IdGenerator.of(1), "name");
PropertyKey age = this.newPropertyKey(IdGenerator.of(2), "age", DataType.INT, Cardinality.SINGLE);
PropertyKey city = this.newPropertyKey(IdGenerator.of(3), "city");
PropertyKey date = this.newPropertyKey(IdGenerator.of(4), "date", DataType.DATE);
PropertyKey weight = this.newPropertyKey(IdGenerator.of(5), "weight", DataType.DOUBLE);
VertexLabel vl = this.newVertexLabel(IdGenerator.of(1), "person", IdStrategy.CUSTOMIZE_NUMBER, name.id(), age.id(), city.id());
EdgeLabel el = this.newEdgeLabel(IdGenerator.of(1), "knows", Frequency.SINGLE, vl.id(), vl.id(), date.id(), weight.id());
HugeVertex source = new HugeVertex(this.graph(), IdGenerator.of(sourceVertexId), vl);
source.addProperty(name, "tom");
source.addProperty(age, 18);
source.addProperty(city, "Beijing");
HugeVertex target = new HugeVertex(this.graph(), IdGenerator.of(targetVertexId), vl);
target.addProperty(name, "cat");
target.addProperty(age, 20);
target.addProperty(city, "Shanghai");
Id id = EdgeId.parse("L123456>1>>L987654");
HugeEdge edge = new HugeEdge(this.graph(), id, el);
Whitebox.setInternalState(edge, "sourceVertex", source);
Whitebox.setInternalState(edge, "targetVertex", target);
edge.assignId();
edge.addProperty(date, new Date());
edge.addProperty(weight, 0.75);
return edge;
}
use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.
the class FakeObjects method newEdge.
public HugeEdge newEdge(String sourceVertexId, String targetVertexId) {
PropertyKey name = this.newPropertyKey(IdGenerator.of(1), "name");
PropertyKey age = this.newPropertyKey(IdGenerator.of(2), "age", DataType.INT, Cardinality.SINGLE);
PropertyKey city = this.newPropertyKey(IdGenerator.of(3), "city");
PropertyKey date = this.newPropertyKey(IdGenerator.of(4), "date", DataType.DATE);
PropertyKey weight = this.newPropertyKey(IdGenerator.of(5), "weight", DataType.DOUBLE);
VertexLabel vl = this.newVertexLabel(IdGenerator.of(1), "person", IdStrategy.CUSTOMIZE_NUMBER, name.id(), age.id(), city.id());
EdgeLabel el = this.newEdgeLabel(IdGenerator.of(1), "knows", Frequency.SINGLE, vl.id(), vl.id(), date.id(), weight.id());
HugeVertex source = new HugeVertex(this.graph(), IdGenerator.of(sourceVertexId), vl);
source.addProperty(name, "tom");
source.addProperty(age, 18);
source.addProperty(city, "Beijing");
HugeVertex target = new HugeVertex(this.graph(), IdGenerator.of(targetVertexId), vl);
target.addProperty(name, "cat");
target.addProperty(age, 20);
target.addProperty(city, "Shanghai");
Id id = EdgeId.parse("L123456>1>>L987654");
HugeEdge edge = new HugeEdge(this.graph(), id, el);
Whitebox.setInternalState(edge, "sourceVertex", source);
Whitebox.setInternalState(edge, "targetVertex", target);
edge.assignId();
edge.addProperty(date, new Date());
edge.addProperty(weight, 0.75);
return edge;
}
use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.
the class CachedGraphTransactionTest method testEdgeCacheClearWhenDeleteVertex.
@Test
public void testEdgeCacheClearWhenDeleteVertex() {
CachedGraphTransaction cache = this.cache();
HugeVertex v1 = this.newVertex(IdGenerator.of(1));
HugeVertex v2 = this.newVertex(IdGenerator.of(2));
HugeVertex v3 = this.newVertex(IdGenerator.of(3));
cache.addVertex(v1);
cache.addVertex(v2);
cache.commit();
HugeEdge edge = this.newEdge(v1, v2);
cache.addEdge(edge);
cache.commit();
Assert.assertTrue(cache.queryEdgesByVertex(IdGenerator.of(1)).hasNext());
Assert.assertTrue(cache.queryEdgesByVertex(IdGenerator.of(2)).hasNext());
Assert.assertEquals(2L, Whitebox.invoke(cache, "edgesCache", "size"));
cache.removeVertex(v3);
cache.commit();
Assert.assertEquals(0L, Whitebox.invoke(cache, "edgesCache", "size"));
Assert.assertTrue(cache.queryEdgesByVertex(IdGenerator.of(1)).hasNext());
Assert.assertTrue(cache.queryEdgesByVertex(IdGenerator.of(2)).hasNext());
Assert.assertEquals(2L, Whitebox.invoke(cache, "edgesCache", "size"));
cache.removeVertex(v1);
cache.commit();
Assert.assertEquals(0L, Whitebox.invoke(cache, "edgesCache", "size"));
Assert.assertFalse(cache.queryEdgesByVertex(IdGenerator.of(2)).hasNext());
}
use of com.baidu.hugegraph.structure.HugeVertex 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.structure.HugeVertex in project incubator-hugegraph by apache.
the class TableSerializer method readVertex.
@Override
public HugeVertex readVertex(HugeGraph graph, BackendEntry backendEntry) {
E.checkNotNull(graph, "serializer graph");
if (backendEntry == null) {
return null;
}
TableBackendEntry entry = this.convertEntry(backendEntry);
assert entry.type().isVertex();
Id id = this.readId(entry.column(HugeKeys.ID));
Number label = entry.column(HugeKeys.LABEL);
Number expiredTime = entry.column(HugeKeys.EXPIRED_TIME);
VertexLabel vertexLabel = VertexLabel.NONE;
if (label != null) {
vertexLabel = graph.vertexLabelOrNone(this.toId(label));
}
HugeVertex vertex = new HugeVertex(graph, id, vertexLabel);
// Parse all properties of a Vertex
this.parseProperties(vertex, entry.row());
// Parse all edges of a Vertex
for (TableBackendEntry.Row edge : entry.subRows()) {
this.parseEdge(edge, vertex, graph);
}
// The expired time is null when this is fake vertex of edge or non-ttl
if (expiredTime != null) {
vertex.expiredTime(expiredTime.longValue());
}
return vertex;
}
Aggregations