use of org.umlg.sqlg.structure.SqlgVertex in project sqlg by pietermartin.
the class TestBatchStreamEdge method createMilCarVertex.
private ArrayList<SqlgVertex> createMilCarVertex() {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
ArrayList<SqlgVertex> result = new ArrayList<>();
this.sqlgGraph.tx().normalBatchModeOn();
for (int i = 1; i < NUMBER_OF_VERTICES + 1; i++) {
Map<String, Object> keyValue = new LinkedHashMap<>();
for (int j = 0; j < 100; j++) {
keyValue.put("name" + j, "aaaaaaaaaa" + i);
}
SqlgVertex car = (SqlgVertex) this.sqlgGraph.addVertex("Car", keyValue);
result.add(car);
if (i % (NUMBER_OF_VERTICES / 10) == 0) {
this.sqlgGraph.tx().commit();
this.sqlgGraph.tx().normalBatchModeOn();
}
}
this.sqlgGraph.tx().commit();
stopWatch.stop();
System.out.println("createMilCarVertex took " + stopWatch.toString());
return result;
}
use of org.umlg.sqlg.structure.SqlgVertex in project sqlg by pietermartin.
the class TestBatchStreamEdge method testStreamPeriod.
@Test
public void testStreamPeriod() throws InterruptedException {
this.sqlgGraph.tx().streamingBatchModeOn();
LinkedHashMap<String, Object> keyValues = new LinkedHashMap<>();
keyValues.put("name", "halo");
keyValues.put("surname", "halo");
for (int i = 0; i < 10; i++) {
keyValues.put("age", i);
this.sqlgGraph.streamVertex("Man", keyValues);
}
this.sqlgGraph.tx().flush();
for (int i = 0; i < 10; i++) {
keyValues.put("age", i);
this.sqlgGraph.streamVertex("Female", keyValues);
}
this.sqlgGraph.tx().flush();
int count = 0;
List<Vertex> men = this.sqlgGraph.traversal().V().hasLabel("Man").toList();
List<Vertex> females = this.sqlgGraph.traversal().V().hasLabel("Female").toList();
LinkedHashMap<String, Object> edgeKeyValues = new LinkedHashMap<>();
Period period = Period.of(1, 2, 3);
edgeKeyValues.put("period", period);
for (Vertex man : men) {
SqlgVertex female = (SqlgVertex) females.get(count++);
((SqlgVertex) man).streamEdge("married", female, edgeKeyValues);
}
this.sqlgGraph.tx().commit();
testStreamPeriod_assert(this.sqlgGraph, period);
if (this.sqlgGraph1 != null) {
Thread.sleep(SLEEP_TIME);
testStreamPeriod_assert(this.sqlgGraph1, period);
}
}
use of org.umlg.sqlg.structure.SqlgVertex in project sqlg by pietermartin.
the class TestBatchStreamVertex method testCanNotAddVertexOnceStreaming.
@Test(expected = IllegalStateException.class)
public void testCanNotAddVertexOnceStreaming() {
this.sqlgGraph.tx().streamingBatchModeOn();
LinkedHashMap<String, Object> keyValues = new LinkedHashMap<>();
keyValues.put("name", "test");
SqlgVertex v2 = (SqlgVertex) this.sqlgGraph.addVertex("A", keyValues);
Assert.fail();
}
use of org.umlg.sqlg.structure.SqlgVertex in project sqlg by pietermartin.
the class TestAddVertexViaMap method testMap.
@Test
public void testMap() {
Map<String, Object> map = new HashMap<>();
map.put("name1", "p1");
map.put("name2", "p2");
map.put("name3", "p3");
Vertex v1 = this.sqlgGraph.addVertex("Person", map);
this.sqlgGraph.tx().commit();
Vertex v2 = this.sqlgGraph.traversal().V().<Vertex>has(T.label, "Person").next();
Assert.assertEquals(v1, v2);
Assert.assertEquals("p1", v2.property("name1").value());
Assert.assertEquals("p2", v2.property("name2").value());
Assert.assertEquals("p3", v2.property("name3").value());
Map<String, Object> edgeMap = new HashMap<>();
edgeMap.put("name1", "p1");
edgeMap.put("name2", "p2");
edgeMap.put("name3", "p3");
Edge e1 = ((SqlgVertex) v1).addEdgeWithMap("e1", v2, edgeMap);
this.sqlgGraph.tx().commit();
Assert.assertEquals("p1", e1.property("name1").value());
Assert.assertEquals("p2", e1.property("name2").value());
Assert.assertEquals("p3", e1.property("name3").value());
}
use of org.umlg.sqlg.structure.SqlgVertex in project sqlg by pietermartin.
the class TestTraversalPerformance method testSpeedWithLargeSchemaFastQuery1.
@Test
public void testSpeedWithLargeSchemaFastQuery1() {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
Map<String, PropertyType> columns = new HashMap<>();
for (int i = 0; i < 100; i++) {
columns.put("property_" + i, PropertyType.STRING);
}
// Create a large schema, it slows the maps down
int NUMBER_OF_SCHEMA_ELEMENTS = 1_000;
for (int i = 0; i < NUMBER_OF_SCHEMA_ELEMENTS; i++) {
VertexLabel person = this.sqlgGraph.getTopology().ensureVertexLabelExist("Person_" + i, columns);
VertexLabel dog = this.sqlgGraph.getTopology().ensureVertexLabelExist("Dog_" + i, columns);
person.ensureEdgeLabelExist("pet_" + i, dog, columns);
if (i % 100 == 0) {
this.sqlgGraph.tx().commit();
}
}
this.sqlgGraph.tx().commit();
stopWatch.stop();
System.out.println("done creating schema time taken " + stopWatch.toString());
stopWatch.reset();
stopWatch.start();
Map<String, Object> columnValues = new HashMap<>();
for (int i = 0; i < 100; i++) {
columnValues.put("property_" + i, "asdasdasd");
}
for (int i = 0; i < NUMBER_OF_SCHEMA_ELEMENTS; i++) {
SqlgVertex person = (SqlgVertex) this.sqlgGraph.addVertex("Person_" + i, columnValues);
SqlgVertex dog = (SqlgVertex) this.sqlgGraph.addVertex("Dog_" + i, columnValues);
person.addEdgeWithMap("pet_" + i, dog, columnValues);
}
this.sqlgGraph.tx().commit();
stopWatch.stop();
System.out.println("done inserting data time taken " + stopWatch.toString());
stopWatch.reset();
stopWatch.start();
for (int i = 0; i < 10_000; i++) {
Assert.assertEquals(1, this.sqlgGraph.traversal().V().hasLabel("Person_0").out("pet_0").toList().size());
}
stopWatch.stop();
System.out.println("total query time " + stopWatch.toString());
}
Aggregations