use of org.umlg.sqlg.structure.SqlgGraph in project sqlg by pietermartin.
the class TestSetProperty method testDateTimeProperties.
@Test
public void testDateTimeProperties() throws Exception {
Vertex v = this.sqlgGraph.addVertex(T.label, "Person", "name", "marko");
LocalDateTime ldt = LocalDateTime.now();
v.property("ldt", ldt);
v.property("ld", ldt.toLocalDate());
LocalTime lt = ldt.toLocalTime().truncatedTo(ChronoUnit.SECONDS);
v.property("lt", lt);
ZonedDateTime zdt = ZonedDateTime.of(LocalDateTime.now(), ZoneId.of("Africa/Johannesburg"));
ZonedDateTime zdt1Fixed = ZonedDateTime.of(zdt.toLocalDateTime(), ZoneId.of("Africa/Johannesburg"));
v.property("zdt", zdt);
ZonedDateTime zdt2 = ZonedDateTime.of(LocalDateTime.now(), ZoneId.of("+02:00"));
ZonedDateTime zdt2Fixed = ZonedDateTime.of(zdt2.toLocalDateTime(), ZoneId.of("GMT+02:00"));
v.property("zdt2", zdt2);
Period p = Period.ofDays(3);
v.property("p", p);
Duration d = Duration.ofHours(12);
v.property("d", d);
Vertex vJ = this.sqlgGraph.addVertex(T.label, "Person", "name", "john");
vJ.addEdge("knows", v);
this.sqlgGraph.tx().commit();
assertProperty(v, "ldt", ldt);
assertProperty(v, "ld", ldt.toLocalDate());
assertProperty(v, "lt", lt);
assertProperty(v, "zdt", zdt1Fixed);
assertProperty(v, "zdt2", zdt2Fixed);
assertProperty(v, "p", p);
assertProperty(v, "d", d);
Vertex vJ2 = sqlgGraph.vertices(vJ.id()).next();
Vertex v2 = vJ2.edges(Direction.OUT).next().inVertex();
assertProperty(v2, "ldt", ldt);
assertProperty(v2, "ld", ldt.toLocalDate());
assertProperty(v2, "lt", lt);
assertProperty(v2, "zdt", zdt);
assertProperty(v2, "zdt2", zdt2Fixed);
assertProperty(v2, "p", p);
assertProperty(v2, "d", d);
this.sqlgGraph.close();
try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
v2 = sqlgGraph1.vertices(v.id()).next();
assertProperty(sqlgGraph1, v2, "ldt", ldt);
assertProperty(sqlgGraph1, v2, "ld", ldt.toLocalDate());
assertProperty(sqlgGraph1, v2, "lt", lt);
assertProperty(sqlgGraph1, v2, "zdt", zdt);
assertProperty(sqlgGraph1, v2, "zdt2", zdt2Fixed);
assertProperty(sqlgGraph1, v2, "p", p);
assertProperty(sqlgGraph1, v2, "d", d);
}
try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
v2 = sqlgGraph1.traversal().V().hasLabel("Person").next();
assertProperty(sqlgGraph1, v2, "ldt", ldt);
assertProperty(sqlgGraph1, v2, "ld", ldt.toLocalDate());
assertProperty(sqlgGraph1, v2, "lt", lt);
assertProperty(sqlgGraph1, v2, "zdt", zdt);
assertProperty(sqlgGraph1, v2, "zdt2", zdt2Fixed);
assertProperty(sqlgGraph1, v2, "p", p);
assertProperty(sqlgGraph1, v2, "d", d);
}
try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
vJ2 = sqlgGraph1.vertices(vJ.id()).next();
v2 = vJ2.edges(Direction.OUT).next().inVertex();
assertProperty(sqlgGraph1, v2, "ldt", ldt);
assertProperty(sqlgGraph1, v2, "ld", ldt.toLocalDate());
assertProperty(sqlgGraph1, v2, "lt", lt);
assertProperty(sqlgGraph1, v2, "zdt", zdt);
assertProperty(sqlgGraph1, v2, "zdt2", zdt2Fixed);
assertProperty(sqlgGraph1, v2, "p", p);
assertProperty(sqlgGraph1, v2, "d", d);
}
}
use of org.umlg.sqlg.structure.SqlgGraph in project sqlg by pietermartin.
the class TestBatch method testBatchUpdateOfLabels.
// this test a 'contains' bug in the update of labels batch logic
@Test
public void testBatchUpdateOfLabels() throws Exception {
this.sqlgGraph.tx().normalBatchModeOn();
Vertex v1 = this.sqlgGraph.addVertex(T.label, "Person", "name", "mike");
Vertex v2 = this.sqlgGraph.addVertex(T.label, "Car", "name", "bmw");
Vertex v3 = this.sqlgGraph.addVertex(T.label, "Car", "name", "bmw");
Vertex v4 = this.sqlgGraph.addVertex(T.label, "Bike", "name", "ktm");
v1.addEdge("bts_aaaaaa", v2);
v1.addEdge("bts_btsalmtos", v4);
v1.addEdge("bts_btsalm", v3);
this.sqlgGraph.tx().commit();
this.sqlgGraph.close();
try (SqlgGraph sqlgGraph = SqlgGraph.open(configuration)) {
v1 = sqlgGraph.traversal().V(v1.id()).next();
Assert.assertEquals(1, sqlgGraph.traversal().V(v1.id()).out("bts_btsalm").count().next().intValue());
Assert.assertEquals(1, sqlgGraph.traversal().V(v1.id()).out("bts_btsalmtos").count().next().intValue());
}
}
use of org.umlg.sqlg.structure.SqlgGraph in project sqlg by pietermartin.
the class TestGis method testUpgradePostGisTypes.
@Test
public void testUpgradePostGisTypes() throws Exception {
Point johannesburgPoint = new Point(26.2044, 28.0456);
Vertex johannesburg = this.sqlgGraph.addVertex(T.label, "Gis", "point", johannesburgPoint);
Point pretoriaPoint = new Point(25.7461, 28.1881);
LineString lineString = new LineString(new Point[] { johannesburgPoint, pretoriaPoint });
Vertex pretoria = this.sqlgGraph.addVertex(T.label, "Gis", "lineString", lineString);
GeographyPoint geographyPointJohannesburg = new GeographyPoint(26.2044, 28.0456);
Vertex johannesburgGeographyPoint = this.sqlgGraph.addVertex(T.label, "Gis", "geographyPoint", geographyPointJohannesburg);
LinearRing linearRing = new LinearRing("0 0, 1 1, 1 2, 1 1, 0 0");
Polygon polygon1 = new Polygon(new LinearRing[] { linearRing });
Vertex johannesburgPolygon = this.sqlgGraph.addVertex(T.label, "Gis", "polygon", polygon1);
linearRing = new LinearRing("0 0, 1 1, 1 2, 1 1, 0 0");
GeographyPolygon geographyPolygon = new GeographyPolygon(new LinearRing[] { linearRing });
Vertex johannesburgGeographyPolygon = this.sqlgGraph.addVertex(T.label, "Gis", "geographyPolygon", geographyPolygon);
this.sqlgGraph.tx().commit();
// Delete the topology
Connection conn = this.sqlgGraph.tx().getConnection();
try (Statement statement = conn.createStatement()) {
statement.execute("DROP SCHEMA " + this.sqlgGraph.getSqlDialect().maybeWrapInQoutes("sqlg_schema") + " CASCADE");
}
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", sqlgGraph1.getSqlDialect().getPublicSchema()).toList();
Assert.assertEquals(1, schemaVertices.size());
List<Vertex> propertyVertices = sqlgGraph1.topology().V().hasLabel("sqlg_schema.schema").has("name", sqlgGraph1.getSqlDialect().getPublicSchema()).out("schema_vertex").has("name", "Gis").out("vertex_property").has("name", "point").toList();
Assert.assertEquals(1, propertyVertices.size());
Assert.assertEquals("POINT", propertyVertices.get(0).value("type"));
Assert.assertEquals(johannesburgPoint, sqlgGraph1.traversal().V(johannesburg.id()).next().value("point"));
Assert.assertEquals(lineString, sqlgGraph1.traversal().V(pretoria.id()).next().value("lineString"));
Assert.assertEquals(geographyPointJohannesburg, sqlgGraph1.traversal().V(johannesburgGeographyPoint.id()).next().value("geographyPoint"));
Assert.assertEquals(polygon1, sqlgGraph1.traversal().V(johannesburgPolygon.id()).next().value("polygon"));
Assert.assertEquals(geographyPolygon, sqlgGraph1.traversal().V(johannesburgGeographyPolygon.id()).next().value("geographyPolygon"));
}
}
use of org.umlg.sqlg.structure.SqlgGraph in project sqlg by pietermartin.
the class SqlgChooseStepStrategy method apply.
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
// noinspection OptionalGetWithoutIsPresent
if (!(traversal.getGraph().get() instanceof SqlgGraph)) {
return;
}
List<ChooseStep> chooseSteps = TraversalHelper.getStepsOfAssignableClass(ChooseStep.class, traversal);
for (ChooseStep<S, E, M> chooseStep : chooseSteps) {
Traversal.Admin<S, M> predicateTraversal = chooseStep.getLocalChildren().get(0);
// The predicate branch step is a local traversal.
// As such if it contains a ReducingBarrierStep the SqlgBranchStepBarrier will not work.
List<ReducingBarrierStep> reducingBarrierSteps = TraversalHelper.getStepsOfAssignableClass(ReducingBarrierStep.class, predicateTraversal);
if (!reducingBarrierSteps.isEmpty()) {
continue;
}
if (predicateTraversal.getSteps().get(predicateTraversal.getSteps().size() - 1) instanceof HasNextStep) {
predicateTraversal.removeStep(predicateTraversal.getSteps().get(predicateTraversal.getSteps().size() - 1));
}
SqlgBranchStepBarrier sqlgBranchStepBarrier = new SqlgChooseStepBarrier<>(traversal, predicateTraversal);
for (String label : chooseStep.getLabels()) {
sqlgBranchStepBarrier.addLabel(label);
}
try {
Field traversalOptionsField = chooseStep.getClass().getSuperclass().getDeclaredField("traversalOptions");
traversalOptionsField.setAccessible(true);
Map<M, List<Traversal.Admin<S, E>>> traversalOptions = (Map<M, List<Traversal.Admin<S, E>>>) traversalOptionsField.get(chooseStep);
for (Map.Entry<M, List<Traversal.Admin<S, E>>> entry : traversalOptions.entrySet()) {
for (Traversal.Admin<S, E> admin : entry.getValue()) {
sqlgBranchStepBarrier.addGlobalChildOption(entry.getKey(), admin);
}
}
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
TraversalHelper.replaceStep(chooseStep, sqlgBranchStepBarrier, chooseStep.getTraversal());
}
}
use of org.umlg.sqlg.structure.SqlgGraph in project sqlg by pietermartin.
the class SqlgWhereTraversalStepStrategy method apply.
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
// noinspection OptionalGetWithoutIsPresent
if (!(traversal.getGraph().get() instanceof SqlgGraph)) {
return;
}
List<WhereTraversalStep> whereTraversalSteps = TraversalHelper.getStepsOfAssignableClass(WhereTraversalStep.class, traversal);
for (WhereTraversalStep<S> whereTraversalStep : whereTraversalSteps) {
List<Traversal.Admin<?, ?>> whereTraversals = whereTraversalStep.getLocalChildren();
Preconditions.checkState(whereTraversals.size() == 1);
Traversal.Admin<?, ?> whereTraversal = whereTraversals.get(0);
// reducing barrier steps like count does not work with Sqlg's barrier optimizations
List<ReducingBarrierStep> reducingBarrierSteps = TraversalHelper.getStepsOfAssignableClassRecursively(ReducingBarrierStep.class, whereTraversal);
if (!reducingBarrierSteps.isEmpty()) {
continue;
}
SqlgWhereTraversalStepBarrier sqlgTraversalFilterStepBarrier = new SqlgWhereTraversalStepBarrier<>(traversal, whereTraversalStep);
for (String label : whereTraversalStep.getLabels()) {
sqlgTraversalFilterStepBarrier.addLabel(label);
}
TraversalHelper.replaceStep(whereTraversalStep, sqlgTraversalFilterStepBarrier, whereTraversalStep.getTraversal());
}
}
Aggregations