use of org.umlg.sqlg.structure.SqlgVertex in project sqlg by pietermartin.
the class TestGremlinCompileWithHas method testOutHasOutHas.
@Test
public void testOutHasOutHas() {
SqlgVertex a1 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "A");
SqlgVertex b1 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
SqlgVertex b2 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "B", "name", "b2");
SqlgVertex b3 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "B", "name", "b3");
a1.addEdge("outB", b1);
a1.addEdge("outB", b2);
a1.addEdge("outB", b3);
SqlgVertex c1 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "C", "name", "c1");
SqlgVertex c2 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "C", "name", "c2");
SqlgVertex c3 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "C", "name", "c3");
SqlgVertex c4 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "C", "name", "c4");
SqlgVertex c5 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "C", "name", "c5");
SqlgVertex c6 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "C", "name", "c6");
SqlgVertex c7 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "C", "name", "c7");
SqlgVertex c8 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "C", "name", "c8");
SqlgVertex c9 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "C", "name", "c9");
b1.addEdge("outC", c1);
b1.addEdge("outC", c2);
b1.addEdge("outC", c3);
b2.addEdge("outC", c4);
b2.addEdge("outC", c5);
b2.addEdge("outC", c6);
b3.addEdge("outC", c7);
b3.addEdge("outC", c8);
b3.addEdge("outC", c9);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Long> traversal = (DefaultGraphTraversal<Vertex, Long>) vertexTraversal(this.sqlgGraph, a1).out().has("name", "b1").out().has("name", "c1").count();
Assert.assertEquals(6, traversal.getSteps().size());
Assert.assertEquals(1, traversal.next().intValue());
Assert.assertEquals(2, traversal.getSteps().size());
DefaultGraphTraversal<Vertex, Vertex> traversal1 = (DefaultGraphTraversal<Vertex, Vertex>) vertexTraversal(this.sqlgGraph, a1).out().has("name", "b1").out().has("name", "c1");
Assert.assertEquals(5, traversal1.getSteps().size());
Assert.assertEquals(c1, traversal1.next());
Assert.assertEquals(1, traversal1.getSteps().size());
DefaultGraphTraversal<Vertex, Long> traversal2 = (DefaultGraphTraversal<Vertex, Long>) vertexTraversal(this.sqlgGraph, a1).out().has("name", "b2").out().has("name", "c5").count();
Assert.assertEquals(6, traversal2.getSteps().size());
Assert.assertEquals(1, traversal2.next().intValue());
Assert.assertEquals(2, traversal2.getSteps().size());
DefaultGraphTraversal<Vertex, Vertex> traversal3 = (DefaultGraphTraversal<Vertex, Vertex>) vertexTraversal(this.sqlgGraph, a1).out().has("name", "b2").out().has("name", "c5");
Assert.assertEquals(5, traversal3.getSteps().size());
Assert.assertEquals(c5, traversal3.next());
Assert.assertEquals(1, traversal3.getSteps().size());
}
use of org.umlg.sqlg.structure.SqlgVertex in project sqlg by pietermartin.
the class TestGremlinCompileWithHas method testOutHasOutHasNotParsed.
@Test
public void testOutHasOutHasNotParsed() {
SqlgVertex a1 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "A");
SqlgVertex b1 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
SqlgVertex b2 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "B", "name", "b2");
SqlgVertex b3 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "B", "name", "b3");
a1.addEdge("outB", b1);
a1.addEdge("outB", b2);
a1.addEdge("outB", b3);
SqlgVertex c1 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "C", "name", "c1");
SqlgVertex c2 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "C", "name", "c2");
SqlgVertex c3 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "C", "name", "c3");
SqlgVertex c4 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "C", "name", "c4");
SqlgVertex c5 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "C", "name", "c5");
SqlgVertex c6 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "C", "name", "c6");
SqlgVertex c7 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "C", "name", "c7");
SqlgVertex c8 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "C", "name", "c8");
SqlgVertex c9 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "C", "name", "c9");
b1.addEdge("outC", c1);
b1.addEdge("outC", c2);
b1.addEdge("outC", c3);
b2.addEdge("outC", c4);
b2.addEdge("outC", c5);
b2.addEdge("outC", c6);
b3.addEdge("outC", c7);
b3.addEdge("outC", c8);
b3.addEdge("outC", c9);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Long> traversal = (DefaultGraphTraversal<Vertex, Long>) vertexTraversal(this.sqlgGraph, a1).out().has("name", "b1").out().has("name", "c1").count();
Assert.assertEquals(6, traversal.getSteps().size());
Assert.assertEquals(1, traversal.next().intValue());
Assert.assertEquals(2, traversal.getSteps().size());
DefaultGraphTraversal<Vertex, Vertex> traversal1 = (DefaultGraphTraversal<Vertex, Vertex>) vertexTraversal(this.sqlgGraph, a1).out().has("name", "b1").out().has("name", "c1");
Assert.assertEquals(5, traversal1.getSteps().size());
Assert.assertEquals(c1, traversal1.next());
Assert.assertEquals(1, traversal1.getSteps().size());
DefaultGraphTraversal<Vertex, Long> traversal2 = (DefaultGraphTraversal<Vertex, Long>) vertexTraversal(this.sqlgGraph, a1).out().has("name", "b2").out().has("name", "c5").count();
Assert.assertEquals(6, traversal2.getSteps().size());
Assert.assertEquals(1, traversal2.next().intValue());
Assert.assertEquals(2, traversal2.getSteps().size());
DefaultGraphTraversal<Vertex, Long> traversal3 = (DefaultGraphTraversal<Vertex, Long>) vertexTraversal(this.sqlgGraph, a1).out().has("name", "b2").has("name", "b2").out().has("name", P.within(Arrays.asList("c5", "c6"))).count();
Assert.assertEquals(6, traversal3.getSteps().size());
Assert.assertEquals(2, traversal3.next().intValue());
Assert.assertEquals(2, traversal3.getSteps().size());
DefaultGraphTraversal<Vertex, Long> traversal4 = (DefaultGraphTraversal<Vertex, Long>) vertexTraversal(this.sqlgGraph, a1).out().has("name", "b2").has("name", "b2").out().has("name", P.eq("c5")).count();
Assert.assertEquals(6, traversal4.getSteps().size());
Assert.assertEquals(1, traversal4.next().intValue());
Assert.assertEquals(2, traversal4.getSteps().size());
}
use of org.umlg.sqlg.structure.SqlgVertex in project sqlg by pietermartin.
the class ReadBenchmark method setup.
@Setup(Level.Iteration)
public void setup() throws Exception {
System.out.println("setup");
this.sqlgGraph = getSqlgGraph();
SqlgUtil.dropDb(this.sqlgGraph);
this.sqlgGraph.tx().commit();
this.sqlgGraph = getSqlgGraph();
this.gt = this.sqlgGraph.traversal();
// Create a graph with degree 3
Map<String, Object> properties = new HashMap<>();
properties.put("a1", "aaaaaaaaaa1");
properties.put("a2", "aaaaaaaaaa2");
properties.put("a3", "aaaaaaaaaa3");
properties.put("a4", "aaaaaaaaaa4");
properties.put("a5", "aaaaaaaaaa5");
properties.put("a6", "aaaaaaaaaa6");
properties.put("a7", "aaaaaaaaaa7");
properties.put("a8", "aaaaaaaaaa8");
properties.put("a9", "aaaaaaaaaa9");
properties.put("a10", "aaaaaaaaaa10");
SqlgVertex a = (SqlgVertex) this.sqlgGraph.addVertex("A", properties);
for (int i = 0; i < 100; i++) {
Vertex b = this.sqlgGraph.addVertex("B", properties);
a.addEdge("ab", b);
for (int j = 0; j < 100; j++) {
Vertex c = this.sqlgGraph.addVertex("C", properties);
b.addEdge("bc", c);
}
}
this.sqlgGraph.tx().commit();
}
use of org.umlg.sqlg.structure.SqlgVertex in project sqlg by pietermartin.
the class CockroachdbDialect method deleteEdges.
private void deleteEdges(SqlgGraph sqlgGraph, SchemaTable schemaTable, List<SqlgVertex> subVertices, Set<SchemaTable> labels, boolean inDirection) {
for (SchemaTable inLabel : labels) {
StringBuilder sql = new StringBuilder();
sql.append("DELETE FROM ");
sql.append(maybeWrapInQoutes(inLabel.getSchema()));
sql.append(".");
sql.append(maybeWrapInQoutes(inLabel.getTable()));
sql.append(" WHERE ");
sql.append(maybeWrapInQoutes(schemaTable.toString() + (inDirection ? Topology.IN_VERTEX_COLUMN_END : Topology.OUT_VERTEX_COLUMN_END)));
sql.append(" IN (");
int count = 1;
for (Vertex vertexToDelete : subVertices) {
sql.append("?");
if (count++ < subVertices.size()) {
sql.append(",");
}
}
sql.append(")");
if (sqlgGraph.getSqlDialect().needsSemicolon()) {
sql.append(";");
}
if (logger.isDebugEnabled()) {
logger.debug(sql.toString());
}
Connection conn = sqlgGraph.tx().getConnection();
try (PreparedStatement preparedStatement = conn.prepareStatement(sql.toString())) {
count = 1;
for (Vertex vertexToDelete : subVertices) {
preparedStatement.setLong(count++, ((RecordId) vertexToDelete.id()).getId());
}
int deleted = preparedStatement.executeUpdate();
if (logger.isDebugEnabled()) {
logger.debug("Deleted " + deleted + " edges from " + inLabel.toString());
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
use of org.umlg.sqlg.structure.SqlgVertex in project sqlg by pietermartin.
the class TestBatchStreamEdge method testStreamDuration.
@Test
public void testStreamDuration() 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<>();
Duration duration = Duration.ofHours(19);
edgeKeyValues.put("duration", duration);
for (Vertex man : men) {
SqlgVertex female = (SqlgVertex) females.get(count++);
((SqlgVertex) man).streamEdge("married", female, edgeKeyValues);
}
this.sqlgGraph.tx().commit();
testStreamDuration_assert(this.sqlgGraph, duration);
if (this.sqlgGraph1 != null) {
Thread.sleep(SLEEP_TIME);
testStreamDuration_assert(this.sqlgGraph1, duration);
}
}
Aggregations