Search in sources :

Example 31 with SqlgGraph

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

the class TestTopologyUpgrade method testGratefulDeadDBUpgrade.

@Test
public void testGratefulDeadDBUpgrade() throws Exception {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsBatchMode());
    loadGratefulDead(this.sqlgGraph);
    Traversal<Vertex, Long> traversal = get_g_V_both_both_count(this.sqlgGraph.traversal());
    Assert.assertEquals(new Long(1406914), traversal.next());
    Assert.assertFalse(traversal.hasNext());
    // Delete the topology
    dropSqlgSchema(this.sqlgGraph);
    this.sqlgGraph.close();
    for (int i = 0; i < 2; i++) {
        try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
            traversal = get_g_V_both_both_count(sqlgGraph1.traversal());
            Assert.assertEquals(new Long(1406914), traversal.next());
            Assert.assertFalse(traversal.hasNext());
        }
    }
}
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 32 with SqlgGraph

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

the class TestTopologyUpgrade method testUpgradeTypesWithMoreThanOneColumn.

@Test
public void testUpgradeTypesWithMoreThanOneColumn() throws Exception {
    ZonedDateTime zonedDateTime = ZonedDateTime.now();
    Duration duration = Duration.ofDays(1);
    Period period = Period.of(1, 1, 1);
    this.sqlgGraph.addVertex(T.label, "A.A", "name", "a1", "zonedDateTime", zonedDateTime);
    this.sqlgGraph.addVertex(T.label, "A.A", "name", "a2", "duration", duration);
    this.sqlgGraph.addVertex(T.label, "A.A", "name", "a3", "period", period);
    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("schema_vertex").has("name", "A").out("vertex_property").has("name", "zonedDateTime").toList();
        Assert.assertEquals(1, propertyVertices.size());
        Assert.assertEquals(PropertyType.ZONEDDATETIME, PropertyType.valueOf(propertyVertices.get(0).value("type")));
        List<Vertex> vertices = sqlgGraph1.traversal().V().hasLabel("A.A").has("name", "a1").toList();
        Assert.assertEquals(1, vertices.size());
        Assert.assertEquals(zonedDateTime, vertices.get(0).value("zonedDateTime"));
        // assert duration
        propertyVertices = sqlgGraph1.topology().V().hasLabel("sqlg_schema.schema").has("name", "A").out("schema_vertex").has("name", "A").out("vertex_property").has("name", "duration").toList();
        Assert.assertEquals(1, propertyVertices.size());
        Assert.assertEquals(PropertyType.DURATION, PropertyType.valueOf(propertyVertices.get(0).value("type")));
        vertices = sqlgGraph1.traversal().V().hasLabel("A.A").has("name", "a2").toList();
        Assert.assertEquals(1, vertices.size());
        Assert.assertEquals(duration, vertices.get(0).value("duration"));
        // assert period
        propertyVertices = sqlgGraph1.topology().V().hasLabel("sqlg_schema.schema").has("name", "A").out("schema_vertex").has("name", "A").out("vertex_property").has("name", "period").toList();
        Assert.assertEquals(1, propertyVertices.size());
        Assert.assertEquals(PropertyType.PERIOD, PropertyType.valueOf(propertyVertices.get(0).value("type")));
        vertices = sqlgGraph1.traversal().V().hasLabel("A.A").has("name", "a3").toList();
        Assert.assertEquals(1, vertices.size());
        Assert.assertEquals(period, vertices.get(0).value("period"));
    }
}
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 33 with SqlgGraph

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

the class TestTopologyUpgrade method multipleSchemas.

@Test
public void multipleSchemas() throws Exception {
    Vertex aPublic = this.sqlgGraph.addVertex(T.label, "APUBLIC", "name", "aPublic");
    Vertex aReal = this.sqlgGraph.addVertex(T.label, "REAL.AREAL", "name", "aReal");
    aPublic.addEdge("a", aReal, "name", "asd");
    aReal.addEdge("a", aPublic, "name", "dsa");
    Vertex bPublic = this.sqlgGraph.addVertex(T.label, "BPUBLIC", "name", "bPublic");
    Vertex bReal = this.sqlgGraph.addVertex(T.label, "REAL.BREAL", "name", "bReal");
    bPublic.addEdge("a", bReal, "name", "asd");
    bReal.addEdge("a", bPublic, "name", "dsa");
    this.sqlgGraph.tx().commit();
    // 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(1, sqlgGraph1.traversal().V(aPublic.id()).in().count().next().intValue());
        Assert.assertEquals(1, sqlgGraph1.traversal().V(aPublic.id()).out().count().next().intValue());
    }
}
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 34 with SqlgGraph

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

the class TestTopologyUpgrade method testUpgradeJsonArrays.

@Test
public void testUpgradeJsonArrays() throws Exception {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().isPostgresql());
    // HSQLDB can not upgrade JSON ARRAY as its indistinguishable from STRING ARRAY.
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsJsonArrayValues());
    ObjectNode json1 = new ObjectMapper().createObjectNode();
    json1.put("halo", "asdasd");
    ObjectNode json2 = new ObjectMapper().createObjectNode();
    json2.put("halo", "asdasd");
    ObjectNode[] jsons = new ObjectNode[] { json1, json2 };
    this.sqlgGraph.addVertex(T.label, "A.A", "name", "a1", "jsons", jsons);
    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 zonedDateTimes
        List<Vertex> propertyVertices = sqlgGraph1.topology().V().hasLabel("sqlg_schema.schema").has("name", "A").out("schema_vertex").has("name", "A").out("vertex_property").has("name", "jsons").toList();
        Assert.assertEquals(1, propertyVertices.size());
        Assert.assertEquals(PropertyType.JSON_ARRAY, PropertyType.valueOf(propertyVertices.get(0).value("type")));
        List<Vertex> vertices = sqlgGraph1.traversal().V().hasLabel("A.A").has("name", "a1").toList();
        Assert.assertEquals(1, vertices.size());
        Assert.assertArrayEquals(jsons, vertices.get(0).value("jsons"));
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 35 with SqlgGraph

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

the class TestTopologyUpgrade method testUpgradeIndex.

@SuppressWarnings("serial")
@Test
public void testUpgradeIndex() throws Exception {
    // with topology
    VertexLabel personVertexLabel = this.sqlgGraph.getTopology().ensureVertexLabelExist("Person", new HashMap<String, PropertyType>() {

        {
            put("firstName", PropertyType.STRING);
            put("lastName", PropertyType.STRING);
        }
    });
    personVertexLabel.ensureIndexExists(IndexType.UNIQUE, new ArrayList<>(personVertexLabel.getProperties().values()));
    Map<String, PropertyType> properties = new HashMap<String, PropertyType>() {

        {
            put("name", PropertyType.STRING);
        }
    };
    VertexLabel dogVertexLabel = this.sqlgGraph.getTopology().ensureVertexLabelExist("Dog", properties);
    dogVertexLabel.ensureIndexExists(IndexType.NON_UNIQUE, new ArrayList<>(dogVertexLabel.getProperties().values()));
    Map<String, PropertyType> eproperties = new HashMap<String, PropertyType>() {

        {
            put("since", PropertyType.LOCALDATE);
        }
    };
    EdgeLabel eLabel = this.sqlgGraph.getTopology().ensureEdgeLabelExist("Owns", personVertexLabel, dogVertexLabel, eproperties);
    eLabel.ensureIndexExists(IndexType.UNIQUE, new ArrayList<>(eLabel.getProperties().values()));
    // test performance
    /*for (int a=0;a<1000;a++){
        	VertexLabel testVertex = this.sqlgGraph.getTopology().ensureVertexLabelExist("Person"+a, new HashMap<String, PropertyType>() {{
                put("firstName", PropertyType.STRING);
                put("lastName", PropertyType.STRING);
            }});
        	testVertex.ensureIndexExists(IndexType.UNIQUE, new ArrayList<>(testVertex.getProperties().values()));

        }*/
    // not supported yet
    /*this.sqlgGraph.getTopology().ensureGlobalUniqueIndexExist(new HashSet<PropertyColumn>() {{
            add(personVertexLabel.getProperty("firstName").get());
            add(dogVertexLabel.getProperty("name").get());
        }});*/
    this.sqlgGraph.tx().commit();
    // sanity
    topologyCheck(this.sqlgGraph);
    // Delete the topology
    dropSqlgSchema(this.sqlgGraph);
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.close();
    // topology will be recreated
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        topologyCheck(sqlgGraph1);
    }
    // from topology
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        topologyCheck(sqlgGraph1);
    }
}
Also used : SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) PropertyType(org.umlg.sqlg.structure.PropertyType) 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