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());
}
}
}
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"));
}
}
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());
}
}
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"));
}
}
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);
}
}
Aggregations