use of com.baidu.hugegraph.structure.HugeEdge 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.HugeEdge 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.HugeEdge 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.HugeEdge in project incubator-hugegraph by apache.
the class RamTableTest method testAddAndQuery.
@Test
public void testAddAndQuery() throws Exception {
HugeGraph graph = this.graph();
int el1 = (int) graph.edgeLabel("el1").id().asLong();
int el2 = (int) graph.edgeLabel("el2").id().asLong();
RamTable table = new RamTable(graph, VERTEX_SIZE, EDGE_SIZE);
long oldSize = table.edgesSize();
// insert edges
for (int i = 0; i < VERTEX_SIZE; i++) {
table.addEdge(true, i, i, Directions.OUT, el1);
Assert.assertEquals(oldSize + 2 * i + 1, table.edgesSize());
table.addEdge(false, i, i + 1, Directions.IN, el2);
Assert.assertEquals(oldSize + 2 * i + 2, table.edgesSize());
}
// query by BOTH
for (int i = 0; i < VERTEX_SIZE; i++) {
Iterator<HugeEdge> edges = table.query(i, Directions.BOTH, 0);
Assert.assertTrue(edges.hasNext());
HugeEdge edge1 = edges.next();
Assert.assertEquals(i, edge1.id().ownerVertexId().asLong());
Assert.assertEquals(i, edge1.id().otherVertexId().asLong());
Assert.assertEquals(Directions.OUT, edge1.direction());
Assert.assertEquals("el1", edge1.label());
Assert.assertTrue(edges.hasNext());
HugeEdge edge2 = edges.next();
Assert.assertEquals(i, edge2.id().ownerVertexId().asLong());
Assert.assertEquals(i + 1L, edge2.id().otherVertexId().asLong());
Assert.assertEquals(Directions.IN, edge2.direction());
Assert.assertEquals("el2", edge2.label());
Assert.assertFalse(edges.hasNext());
}
// query by OUT
for (int i = 0; i < VERTEX_SIZE; i++) {
Iterator<HugeEdge> edges = table.query(i, Directions.OUT, el1);
Assert.assertTrue(edges.hasNext());
HugeEdge edge1 = edges.next();
Assert.assertEquals(i, edge1.id().ownerVertexId().asLong());
Assert.assertEquals(i, edge1.id().otherVertexId().asLong());
Assert.assertEquals(Directions.OUT, edge1.direction());
Assert.assertEquals("el1", edge1.label());
Assert.assertFalse(edges.hasNext());
}
// query by IN
for (int i = 0; i < VERTEX_SIZE; i++) {
Iterator<HugeEdge> edges = table.query(i, Directions.IN, el2);
Assert.assertTrue(edges.hasNext());
HugeEdge edge1 = edges.next();
Assert.assertEquals(i, edge1.id().ownerVertexId().asLong());
Assert.assertEquals(i + 1L, edge1.id().otherVertexId().asLong());
Assert.assertEquals(Directions.IN, edge1.direction());
Assert.assertEquals("el2", edge1.label());
Assert.assertFalse(edges.hasNext());
}
// query by BOTH & label 1
for (int i = 0; i < VERTEX_SIZE; i++) {
Iterator<HugeEdge> edges = table.query(i, Directions.BOTH, el1);
Assert.assertTrue(edges.hasNext());
HugeEdge edge1 = edges.next();
Assert.assertEquals(i, edge1.id().ownerVertexId().asLong());
Assert.assertEquals(i, edge1.id().otherVertexId().asLong());
Assert.assertEquals(Directions.OUT, edge1.direction());
Assert.assertEquals("el1", edge1.label());
Assert.assertFalse(edges.hasNext());
}
// query by BOTH & label 2
for (int i = 0; i < VERTEX_SIZE; i++) {
Iterator<HugeEdge> edges = table.query(i, Directions.BOTH, el2);
Assert.assertTrue(edges.hasNext());
HugeEdge edge1 = edges.next();
Assert.assertEquals(i, edge1.id().ownerVertexId().asLong());
Assert.assertEquals(i + 1L, edge1.id().otherVertexId().asLong());
Assert.assertEquals(Directions.IN, edge1.direction());
Assert.assertEquals("el2", edge1.label());
Assert.assertFalse(edges.hasNext());
}
// query non-exist vertex
Iterator<HugeEdge> edges = table.query(VERTEX_SIZE, Directions.BOTH, 0);
Assert.assertFalse(edges.hasNext());
}
use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.
the class RamTableTest method testAddAndQueryWithoutAdjEdges.
@Test
public void testAddAndQueryWithoutAdjEdges() throws Exception {
HugeGraph graph = this.graph();
int el1 = (int) graph.edgeLabel("el1").id().asLong();
int el2 = (int) graph.edgeLabel("el2").id().asLong();
RamTable table = new RamTable(graph, VERTEX_SIZE, EDGE_SIZE);
long oldSize = table.edgesSize();
// insert edges
for (int i = 0; i < VERTEX_SIZE; i++) {
if (i % 3 != 0) {
// don't insert edges for 2/3 vertices
continue;
}
table.addEdge(true, i, i, Directions.OUT, el1);
Assert.assertEquals(oldSize + i + 1, table.edgesSize());
table.addEdge(false, i, i, Directions.OUT, el2);
Assert.assertEquals(oldSize + i + 2, table.edgesSize());
table.addEdge(false, i, i + 1, Directions.IN, el2);
Assert.assertEquals(oldSize + i + 3, table.edgesSize());
}
// query by BOTH
for (int i = 0; i < VERTEX_SIZE; i++) {
Iterator<HugeEdge> edges = table.query(i, Directions.BOTH, 0);
if (i % 3 != 0) {
Assert.assertFalse(edges.hasNext());
continue;
}
Assert.assertTrue(edges.hasNext());
HugeEdge edge1 = edges.next();
Assert.assertEquals(i, edge1.id().ownerVertexId().asLong());
Assert.assertEquals(i, edge1.id().otherVertexId().asLong());
Assert.assertEquals(Directions.OUT, edge1.direction());
Assert.assertEquals("el1", edge1.label());
Assert.assertTrue(edges.hasNext());
HugeEdge edge2 = edges.next();
Assert.assertEquals(i, edge2.id().ownerVertexId().asLong());
Assert.assertEquals(i, edge2.id().otherVertexId().asLong());
Assert.assertEquals(Directions.OUT, edge2.direction());
Assert.assertEquals("el2", edge2.label());
Assert.assertTrue(edges.hasNext());
HugeEdge edge3 = edges.next();
Assert.assertEquals(i, edge3.id().ownerVertexId().asLong());
Assert.assertEquals(i + 1L, edge3.id().otherVertexId().asLong());
Assert.assertEquals(Directions.IN, edge3.direction());
Assert.assertEquals("el2", edge3.label());
Assert.assertFalse(edges.hasNext());
}
}
Aggregations