Search in sources :

Example 16 with SqlgVertex

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());
}
Also used : SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 17 with SqlgVertex

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());
}
Also used : SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 18 with SqlgVertex

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();
}
Also used : SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) HashMap(java.util.HashMap) SqlgVertex(org.umlg.sqlg.structure.SqlgVertex)

Example 19 with SqlgVertex

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);
        }
    }
}
Also used : SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SQLException(java.sql.SQLException) SchemaTable(org.umlg.sqlg.structure.SchemaTable) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 20 with SqlgVertex

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);
    }
}
Also used : SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) LinkedHashMap(java.util.LinkedHashMap) BaseTest(org.umlg.sqlg.test.BaseTest)

Aggregations

SqlgVertex (org.umlg.sqlg.structure.SqlgVertex)27 BaseTest (org.umlg.sqlg.test.BaseTest)22 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)17 LinkedHashMap (java.util.LinkedHashMap)16 StopWatch (org.apache.commons.lang3.time.StopWatch)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)3 DefaultGraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal)3 ArrayList (java.util.ArrayList)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 Edge (org.apache.tinkerpop.gremlin.structure.Edge)1 PropertyType (org.umlg.sqlg.structure.PropertyType)1 SchemaTable (org.umlg.sqlg.structure.SchemaTable)1 VertexLabel (org.umlg.sqlg.structure.topology.VertexLabel)1