Search in sources :

Example 56 with SqlgGraph

use of org.umlg.sqlg.structure.SqlgGraph in project sqlg by pietermartin.

the class TestTopologyUpgrade method testUpgradeTypesWithMoreThanOneColumnOnEdgeArrays.

@Test
public void testUpgradeTypesWithMoreThanOneColumnOnEdgeArrays() throws Exception {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsDurationArrayValues());
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsPeriodArrayValues());
    ZonedDateTime[] zonedDateTimes = new ZonedDateTime[] { ZonedDateTime.now(), ZonedDateTime.now().minusMonths(1), ZonedDateTime.now().minusMonths(2) };
    Duration[] durations = new Duration[] { Duration.ofDays(1), Duration.ofDays(2), Duration.ofDays(3) };
    Period[] periods = new Period[] { Period.of(1, 1, 1), Period.of(2, 2, 2), Period.of(3, 3, 3) };
    Vertex a1 = this.sqlgGraph.addVertex(T.label, "A.A", "name", "a1");
    Vertex a2 = this.sqlgGraph.addVertex(T.label, "A.A", "name", "a2");
    a1.addEdge("ab", a2, "zonedDateTimes", zonedDateTimes, "durations", durations, "periods", periods);
    this.sqlgGraph.tx().commit();
    // Delete the topology
    dropSqlgSchema(this.sqlgGraph);
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.close();
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        List<Vertex> schemaVertices = sqlgGraph1.topology().V().hasLabel("sqlg_schema.schema").has("name", "A").toList();
        Assert.assertEquals(1, schemaVertices.size());
        // assert zonedDateTime
        List<Vertex> propertyVertices = sqlgGraph1.topology().V().hasLabel("sqlg_schema.schema").has("name", "A").out(Topology.SQLG_SCHEMA_SCHEMA_VERTEX_EDGE).has(Topology.SQLG_SCHEMA_VERTEX_LABEL_NAME, "A").out(Topology.SQLG_SCHEMA_OUT_EDGES_EDGE).out(Topology.SQLG_SCHEMA_EDGE_PROPERTIES_EDGE).has(Topology.SQLG_SCHEMA_PROPERTY_NAME, "zonedDateTimes").toList();
        Assert.assertEquals(1, propertyVertices.size());
        Assert.assertEquals(PropertyType.ZONEDDATETIME_ARRAY, PropertyType.valueOf(propertyVertices.get(0).value("type")));
        List<Edge> edges = sqlgGraph1.traversal().E().hasLabel("ab").toList();
        Assert.assertEquals(1, edges.size());
        Assert.assertArrayEquals(zonedDateTimes, edges.get(0).value("zonedDateTimes"));
        Assert.assertArrayEquals(durations, edges.get(0).value("durations"));
        Assert.assertArrayEquals(periods, edges.get(0).value("periods"));
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) Edge(org.apache.tinkerpop.gremlin.structure.Edge) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 57 with SqlgGraph

use of org.umlg.sqlg.structure.SqlgGraph in project sqlg by pietermartin.

the class TestTopologyUpgrade method testCustomIndexIgnored.

// The asdasd index is for a property that foes not exist, it will be ignored when loading the topology.
@Test
public void testCustomIndexIgnored() throws Exception {
    // TODO one day for HSQLDB and the rest
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().isPostgresql());
    Map<String, PropertyType> properties = new HashMap<String, PropertyType>() {

        {
            put("name", PropertyType.STRING);
        }
    };
    Schema hour = this.sqlgGraph.getTopology().ensureSchemaExist("A");
    VertexLabel vertexLabel = hour.ensureVertexLabelExist("A", properties);
    PropertyColumn propertyColumn = vertexLabel.getProperty("name").get();
    vertexLabel.ensureIndexExists(IndexType.NON_UNIQUE, Collections.singletonList(propertyColumn));
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.addVertex(T.label, "A.A", "name", "aaaa");
    Connection conn = this.sqlgGraph.tx().getConnection();
    try (Statement statement = conn.createStatement()) {
        statement.execute("CREATE INDEX \"asdasd\" ON \"A\".\"V_A\" USING btree (left('name', 1)) ");
    }
    this.sqlgGraph.tx().commit();
    // Delete the topology
    dropSqlgSchema(this.sqlgGraph);
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.close();
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        Assert.assertEquals(1, sqlgGraph1.traversal().V().count().next().intValue());
        Assert.assertEquals(1, sqlgGraph1.getTopology().getSchema("A").get().getVertexLabel("A").get().getIndexes().size());
    }
}
Also used : SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) Statement(java.sql.Statement) Connection(java.sql.Connection) PropertyType(org.umlg.sqlg.structure.PropertyType) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 58 with SqlgGraph

use of org.umlg.sqlg.structure.SqlgGraph in project sqlg by pietermartin.

the class TestTopologyUpgrade method testUpgradePropertiesAcrossSchema.

@Test
public void testUpgradePropertiesAcrossSchema() throws Exception {
    this.sqlgGraph.addVertex(T.label, "A.A", "name", "a1", "name1", "a11");
    this.sqlgGraph.addVertex(T.label, "B.A", "name", "b1", "name2", "b22");
    this.sqlgGraph.tx().commit();
    // Delete the topology
    dropSqlgSchema(this.sqlgGraph);
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.close();
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        List<Vertex> schemaVertices = sqlgGraph1.topology().V().hasLabel("sqlg_schema.schema").has("name", "A").toList();
        Assert.assertEquals(1, schemaVertices.size());
        List<Vertex> propertyVertices = sqlgGraph1.topology().V().hasLabel("sqlg_schema.schema").has("name", "A").out("schema_vertex").has("name", "A").out("vertex_property").toList();
        Assert.assertEquals(2, propertyVertices.size());
        propertyVertices = sqlgGraph1.topology().V().hasLabel("sqlg_schema.schema").has("name", "B").out("schema_vertex").has("name", "A").out("vertex_property").toList();
        Assert.assertEquals(2, propertyVertices.size());
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 59 with SqlgGraph

use of org.umlg.sqlg.structure.SqlgGraph in project sqlg by pietermartin.

the class TestTopologyUpgrade method testNonEdgeNonVerticeTablesIgnored.

@Test
public void testNonEdgeNonVerticeTablesIgnored() throws Exception {
    // Drop these tables in case they are hanging around, Sqlg only drops V_ and E_ tables.
    Connection conn = this.sqlgGraph.tx().getConnection();
    try (Statement statement = conn.createStatement()) {
        statement.execute("DROP TABLE IF EXISTS " + this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(this.sqlgGraph.getSqlDialect().getPublicSchema()) + "." + this.sqlgGraph.getSqlDialect().maybeWrapInQoutes("EVENT"));
    }
    try (Statement statement = conn.createStatement()) {
        statement.execute("DROP TABLE IF EXISTS " + this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(this.sqlgGraph.getSqlDialect().getPublicSchema()) + "." + this.sqlgGraph.getSqlDialect().maybeWrapInQoutes("VIKINGS"));
    }
    sqlgGraph.tx().commit();
    // with topology
    Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "john");
    Object idA1 = a1.id();
    Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "joe");
    Object idB1 = b1.id();
    a1.addEdge("knows", b1, "name", "hithere");
    this.sqlgGraph.tx().commit();
    // Create some user tables that should be ignored by sqlg
    conn = this.sqlgGraph.tx().getConnection();
    try (Statement statement = conn.createStatement()) {
        statement.execute(this.sqlgGraph.getSqlDialect().createTableStatement() + this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(this.sqlgGraph.getSqlDialect().getPublicSchema()) + "." + this.sqlgGraph.getSqlDialect().maybeWrapInQoutes("EVENT") + "(ID INT)");
    }
    try (Statement statement = conn.createStatement()) {
        statement.execute(this.sqlgGraph.getSqlDialect().createTableStatement() + this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(this.sqlgGraph.getSqlDialect().getPublicSchema()) + "." + this.sqlgGraph.getSqlDialect().maybeWrapInQoutes("VIKINGS") + "(ID INT)");
    }
    // Delete the topology
    dropSqlgSchema(this.sqlgGraph);
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.close();
    // topology will be recreated
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        Assert.assertEquals(2, sqlgGraph1.traversal().V().count().next().intValue());
        Assert.assertEquals(1, sqlgGraph1.traversal().E().count().next().intValue());
        Assert.assertTrue(sqlgGraph1.traversal().V().hasLabel("A").hasNext());
        Assert.assertTrue(sqlgGraph1.traversal().V().hasLabel("B").hasNext());
        Assert.assertEquals(1, sqlgGraph1.traversal().V().hasLabel("A").count().next().intValue());
        Assert.assertEquals(1, sqlgGraph1.traversal().V().hasLabel("B").count().next().intValue());
        Vertex a = sqlgGraph1.traversal().V().hasLabel("A").next();
        Assert.assertEquals(idA1, a.id());
        Vertex b = sqlgGraph1.traversal().V().hasLabel("B").next();
        Assert.assertEquals(idB1, b.id());
        Assert.assertEquals(1, sqlgGraph1.traversal().V(a).out("knows").count().next().intValue());
        Assert.assertEquals(b, sqlgGraph1.traversal().V(a).out("knows").next());
        Assert.assertEquals(1, sqlgGraph1.traversal().V(b).in("knows").count().next().intValue());
        Assert.assertEquals(a, sqlgGraph1.traversal().V(b).in("knows").next());
        Assert.assertEquals(1, sqlgGraph1.traversal().V(a).properties("name").count().next().intValue());
        Assert.assertTrue(sqlgGraph1.traversal().V(a).properties("name").next().isPresent());
        Assert.assertEquals("john", sqlgGraph1.traversal().V(a).properties("name").next().value());
        Assert.assertEquals(1, sqlgGraph1.traversal().V(a).outE("knows").properties("name").count().next().intValue());
        Assert.assertTrue(sqlgGraph1.traversal().V(a).outE("knows").properties("name").next().isPresent());
        Assert.assertEquals("hithere", sqlgGraph1.traversal().V(a).outE("knows").properties("name").next().value());
        Assert.assertEquals(2, sqlgGraph1.getTopology().getPublicSchema().getVertexLabels().size());
        conn = sqlgGraph1.tx().getConnection();
        try (Statement statement = conn.createStatement()) {
            statement.execute("DROP TABLE " + this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(this.sqlgGraph.getSqlDialect().getPublicSchema()) + "." + this.sqlgGraph.getSqlDialect().maybeWrapInQoutes("EVENT"));
        }
        try (Statement statement = conn.createStatement()) {
            statement.execute("DROP TABLE " + this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(this.sqlgGraph.getSqlDialect().getPublicSchema()) + "." + this.sqlgGraph.getSqlDialect().maybeWrapInQoutes("VIKINGS"));
        }
        sqlgGraph1.tx().commit();
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) Statement(java.sql.Statement) Connection(java.sql.Connection) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 60 with SqlgGraph

use of org.umlg.sqlg.structure.SqlgGraph in project sqlg by pietermartin.

the class TestTopologyUpgrade method testUpgradeFloatArrays.

@Test
public void testUpgradeFloatArrays() throws Exception {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsFloatValues());
    Float[] floats = new Float[] { 1F, 2F, 3F };
    float[] floats2 = new float[] { 1F, 2F, 3F };
    this.sqlgGraph.addVertex(T.label, "A", "floats", floats, "floats2", floats2);
    this.sqlgGraph.tx().commit();
    // Delete the topology
    dropSqlgSchema(this.sqlgGraph);
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.close();
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        Assert.assertArrayEquals(floats, sqlgGraph1.traversal().V().hasLabel("A").next().value("floats"));
        Assert.assertArrayEquals(floats, sqlgGraph1.traversal().V().hasLabel("A").next().value("floats2"));
    }
}
Also used : SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Aggregations

SqlgGraph (org.umlg.sqlg.structure.SqlgGraph)75 Test (org.junit.Test)68 BaseTest (org.umlg.sqlg.test.BaseTest)64 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)44 ConfigurationException (org.apache.commons.configuration.ConfigurationException)10 PropertyVetoException (java.beans.PropertyVetoException)9 IOException (java.io.IOException)9 Connection (java.sql.Connection)7 Edge (org.apache.tinkerpop.gremlin.structure.Edge)6 ResultSet (java.sql.ResultSet)4 Configuration (org.apache.commons.configuration.Configuration)4 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)4 ReducingBarrierStep (org.apache.tinkerpop.gremlin.process.traversal.step.util.ReducingBarrierStep)4 Statement (java.sql.Statement)3 PropertyType (org.umlg.sqlg.structure.PropertyType)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 URL (java.net.URL)2 DatabaseMetaData (java.sql.DatabaseMetaData)2 PreparedStatement (java.sql.PreparedStatement)2