use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.
the class KneighborTraverser method customizedKneighbor.
public KneighborRecords customizedKneighbor(Id source, EdgeStep step, int maxDepth, long limit) {
E.checkNotNull(source, "source vertex id");
this.checkVertexExist(source, "source vertex");
checkPositive(maxDepth, "k-neighbor max_depth");
checkLimit(limit);
boolean concurrent = maxDepth >= this.concurrentDepth();
KneighborRecords records = new KneighborRecords(concurrent, source, true);
Consumer<Id> consumer = v -> {
if (this.reachLimit(limit, records.size())) {
return;
}
Iterator<Edge> edges = edgesOfVertex(v, step);
while (!this.reachLimit(limit, records.size()) && edges.hasNext()) {
Id target = ((HugeEdge) edges.next()).id().otherVertexId();
records.addPath(v, target);
}
};
while (maxDepth-- > 0) {
records.startOneLayer(true);
traverseIds(records.keys(), consumer, concurrent);
records.finishOneLayer();
}
return records;
}
use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.
the class RamTableTest method testReloadAndQuery.
@Test
public void testReloadAndQuery() throws Exception {
HugeGraph graph = this.graph();
// insert vertices and edges
for (int i = 0; i < 100; i++) {
Vertex v1 = graph.addVertex(T.label, "vl1", T.id, i);
Vertex v2 = graph.addVertex(T.label, "vl1", T.id, i + 100);
v1.addEdge("el1", v2);
}
graph.tx().commit();
for (int i = 1000; i < 1100; i++) {
Vertex v1 = graph.addVertex(T.label, "vl2", T.id, i);
Vertex v2 = graph.addVertex(T.label, "vl2", T.id, i + 100);
v1.addEdge("el2", v2);
}
graph.tx().commit();
// reload ramtable
Whitebox.invoke(graph.getClass(), "reloadRamtable", graph);
// query edges
for (int i = 0; i < 100; i++) {
Iterator<Edge> edges = this.edgesOfVertex(IdGenerator.of(i), Directions.OUT, null);
Assert.assertTrue(edges.hasNext());
HugeEdge edge = (HugeEdge) edges.next();
Assert.assertEquals(i + 100, edge.id().otherVertexId().asLong());
Assert.assertEquals(Directions.OUT, edge.direction());
Assert.assertEquals("el1", edge.label());
Assert.assertFalse(edges.hasNext());
}
for (int i = 1000; i < 1100; i++) {
Iterator<Edge> edges = this.edgesOfVertex(IdGenerator.of(i), Directions.OUT, null);
Assert.assertTrue(edges.hasNext());
HugeEdge edge = (HugeEdge) edges.next();
Assert.assertEquals(i + 100, edge.id().otherVertexId().asLong());
Assert.assertEquals(Directions.OUT, edge.direction());
Assert.assertEquals("el2", edge.label());
Assert.assertFalse(edges.hasNext());
}
}
use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.
the class BinaryScatterSerializerTest method testVertex.
@Test
public void testVertex() {
HugeConfig config = FakeObjects.newConfig();
BinaryScatterSerializer ser = new BinaryScatterSerializer(config);
HugeEdge edge = new FakeObjects().newEdge(123, 456);
BackendEntry entry1 = ser.writeVertex(edge.sourceVertex());
HugeVertex vertex1 = ser.readVertex(edge.graph(), entry1);
Assert.assertEquals(edge.sourceVertex(), vertex1);
assertCollectionEquals(edge.sourceVertex().getProperties(), vertex1.getProperties());
BackendEntry entry2 = ser.writeVertex(edge.targetVertex());
HugeVertex vertex2 = ser.readVertex(edge.graph(), entry2);
Assert.assertEquals(edge.targetVertex(), vertex2);
assertCollectionEquals(edge.targetVertex().getProperties(), vertex2.getProperties());
Whitebox.setInternalState(vertex2, "removed", true);
Assert.assertTrue(vertex2.removed());
BackendEntry entry3 = ser.writeVertex(vertex2);
Assert.assertEquals(0, entry3.columnsSize());
Assert.assertNull(ser.readVertex(edge.graph(), null));
}
use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.
the class RolePermissionTest method testHugeResourceFilterVertexOrEdge.
@Test
public void testHugeResourceFilterVertexOrEdge() {
HugeResource all = HugeResource.ALL;
// vertex & edge
FakeObjects fo = new FakeObjects();
HugeEdge edge = fo.newEdge(1, 2);
ResourceObject<?> r1 = ResourceObject.of("g1", edge.sourceVertex());
ResourceObject<?> r2 = ResourceObject.of("g1", edge.targetVertex());
ResourceObject<?> r3 = ResourceObject.of("g1", edge);
Assert.assertTrue(all.filter(r1));
Assert.assertTrue(all.filter(r2));
Assert.assertTrue(all.filter(r3));
HugeResource vr = new HugeResource(ResourceType.VERTEX, HugeResource.ANY, null);
Assert.assertTrue(vr.filter(r1));
Assert.assertTrue(vr.filter(r2));
Assert.assertFalse(vr.filter(r3));
vr = new HugeResource(ResourceType.VERTEX, "person", null);
Assert.assertTrue(vr.filter(r1));
Assert.assertTrue(vr.filter(r2));
Assert.assertFalse(vr.filter(r3));
vr = new HugeResource(ResourceType.VERTEX, "person", ImmutableMap.of("city", "Beijing"));
Assert.assertTrue(vr.filter(r1));
Assert.assertFalse(vr.filter(r2));
Assert.assertFalse(vr.filter(r3));
vr = new HugeResource(ResourceType.VERTEX, "person", ImmutableMap.of("city", "Shanghai"));
Assert.assertFalse(vr.filter(r1));
Assert.assertTrue(vr.filter(r2));
Assert.assertFalse(vr.filter(r3));
vr = new HugeResource(ResourceType.VERTEX, "person", ImmutableMap.of("city", "P.within(\"Beijing\", \"Shanghai\")"));
Assert.assertTrue(vr.filter(r1));
Assert.assertTrue(vr.filter(r2));
Assert.assertFalse(vr.filter(r3));
vr = new HugeResource(ResourceType.VERTEX, "person", ImmutableMap.of("age", "P.gt(18)"));
Assert.assertFalse(vr.filter(r1));
Assert.assertTrue(vr.filter(r2));
Assert.assertFalse(vr.filter(r3));
vr = new HugeResource(ResourceType.VERTEX, "person", ImmutableMap.of("age", "P.between(20, 21)"));
Assert.assertFalse(vr.filter(r1));
Assert.assertTrue(vr.filter(r2));
Assert.assertFalse(vr.filter(r3));
vr = new HugeResource(ResourceType.VERTEX, "person", ImmutableMap.of("age", "P.between(18, 21)"));
Assert.assertTrue(vr.filter(r1));
Assert.assertTrue(vr.filter(r2));
Assert.assertFalse(vr.filter(r3));
HugeResource er = new HugeResource(ResourceType.EDGE, "knows", null);
Assert.assertFalse(er.filter(r1));
Assert.assertFalse(er.filter(r2));
Assert.assertTrue(er.filter(r3));
er = new HugeResource(ResourceType.EDGE, "knows", ImmutableMap.of("weight", "P.gt(0.7)"));
Assert.assertFalse(er.filter(r1));
Assert.assertFalse(er.filter(r2));
Assert.assertTrue(er.filter(r3));
er = new HugeResource(ResourceType.EDGE, "knows", ImmutableMap.of("weight", "P.gt(0.8)"));
Assert.assertFalse(er.filter(r1));
Assert.assertFalse(er.filter(r2));
Assert.assertFalse(er.filter(r3));
er = new HugeResource(ResourceType.EDGE, "knows", ImmutableMap.of("weight", "P.lt(0.8)"));
Assert.assertFalse(er.filter(r1));
Assert.assertFalse(er.filter(r2));
Assert.assertTrue(er.filter(r3));
}
use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.
the class BinarySerializerTest method testVertexForPartition.
@Test
public void testVertexForPartition() {
BinarySerializer ser = new BinarySerializer(true, true, true);
HugeEdge edge = new FakeObjects().newEdge("123", "456");
BackendEntry entry1 = ser.writeVertex(edge.sourceVertex());
HugeVertex vertex1 = ser.readVertex(edge.graph(), entry1);
Assert.assertEquals(edge.sourceVertex(), vertex1);
assertCollectionEquals(edge.sourceVertex().getProperties(), vertex1.getProperties());
BackendEntry entry2 = ser.writeVertex(edge.targetVertex());
HugeVertex vertex2 = ser.readVertex(edge.graph(), entry2);
Assert.assertEquals(edge.targetVertex(), vertex2);
assertCollectionEquals(edge.targetVertex().getProperties(), vertex2.getProperties());
Whitebox.setInternalState(vertex2, "removed", true);
Assert.assertTrue(vertex2.removed());
BackendEntry entry3 = ser.writeVertex(vertex2);
Assert.assertEquals(0, entry3.columnsSize());
Assert.assertNull(ser.readVertex(edge.graph(), null));
}
Aggregations