use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestHasLabelAndId method testInWithHasLabel.
@Test
public void testInWithHasLabel() {
Vertex a = this.sqlgGraph.addVertex(T.label, "A");
Vertex b = this.sqlgGraph.addVertex(T.label, "B");
Vertex c = this.sqlgGraph.addVertex(T.label, "C");
Vertex d = this.sqlgGraph.addVertex(T.label, "D");
b.addEdge("ab", a);
c.addEdge("ac", a);
d.addEdge("ad", a);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").in().hasLabel("B");
List<Vertex> vertices = traversal.toList();
Assert.assertEquals(1, vertices.size());
Assert.assertEquals(1, traversal.getSteps().size());
Assert.assertTrue(traversal.getSteps().get(0) instanceof SqlgGraphStep);
SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) traversal.getSteps().get(0);
Assert.assertEquals(2, sqlgGraphStep.getReplacedSteps().size());
ReplacedStep replacedStep = (ReplacedStep) sqlgGraphStep.getReplacedSteps().get(0);
Assert.assertEquals(1, replacedStep.getLabelHasContainers().size());
replacedStep = (ReplacedStep) sqlgGraphStep.getReplacedSteps().get(1);
Assert.assertEquals(1, replacedStep.getLabelHasContainers().size());
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestHasLabelAndId method testInWithHasLabelAndHasWithinId.
@Test
public void testInWithHasLabelAndHasWithinId() {
Vertex a = this.sqlgGraph.addVertex(T.label, "A");
Vertex b = this.sqlgGraph.addVertex(T.label, "B");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B");
Vertex c = this.sqlgGraph.addVertex(T.label, "C");
Vertex d = this.sqlgGraph.addVertex(T.label, "D");
b.addEdge("ab", a);
b2.addEdge("ab", a);
c.addEdge("ac", a);
d.addEdge("ad", a);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").in().hasLabel("B").has(T.id, P.within(b.id(), b2.id(), c.id()));
List<Vertex> vertices = traversal.toList();
Assert.assertEquals(2, vertices.size());
Assert.assertEquals(1, traversal.getSteps().size());
Assert.assertTrue(traversal.getSteps().get(0) instanceof SqlgGraphStep);
SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) traversal.getSteps().get(0);
Assert.assertEquals(2, sqlgGraphStep.getReplacedSteps().size());
ReplacedStep replacedStep = (ReplacedStep) sqlgGraphStep.getReplacedSteps().get(0);
Assert.assertEquals(1, replacedStep.getLabelHasContainers().size());
replacedStep = (ReplacedStep) sqlgGraphStep.getReplacedSteps().get(1);
Assert.assertEquals(2, replacedStep.getLabelHasContainers().size());
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestHasLabelAndId method testConsecutiveEqHasIdAndLabels3HasIdWithin.
@Test
public void testConsecutiveEqHasIdAndLabels3HasIdWithin() {
Vertex a = this.sqlgGraph.addVertex(T.label, "A");
Vertex b = this.sqlgGraph.addVertex(T.label, "B");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B");
Vertex b3 = this.sqlgGraph.addVertex(T.label, "B");
Vertex c = this.sqlgGraph.addVertex(T.label, "C");
Vertex d = this.sqlgGraph.addVertex(T.label, "D");
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("B").has(T.id, P.without(b.id(), b2.id()));
List<Vertex> vertices = traversal.toList();
Assert.assertEquals(1, vertices.size());
Assert.assertEquals(1, traversal.getSteps().size());
Assert.assertEquals(b3, vertices.get(0));
Assert.assertTrue(traversal.getSteps().get(0) instanceof SqlgGraphStep);
SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) traversal.getSteps().get(0);
Assert.assertEquals(1, sqlgGraphStep.getReplacedSteps().size());
ReplacedStep replacedStep = (ReplacedStep) sqlgGraphStep.getReplacedSteps().get(0);
// without merges its label hasContainer into the previous labelHasContainer
Assert.assertEquals(1, replacedStep.getLabelHasContainers().size());
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestLocalEdgeOtherVertexStep method testEdgeOtherVertexStepDeeper.
@Test
public void testEdgeOtherVertexStepDeeper() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
Vertex c1 = this.sqlgGraph.addVertex(T.label, "C", "name", "c1");
Edge e1 = a1.addEdge("ab", b1);
b1.addEdge("bc", c1);
this.sqlgGraph.tx().commit();
List<Vertex> vertices = this.sqlgGraph.traversal().V(a1).local(__.outE().otherV().out()).toList();
assertEquals(1, vertices.size());
assertEquals(c1, vertices.get(0));
DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal().V(a1).local(__.outE().otherV().out()).path();
List<Path> paths = traversal.toList();
for (Path path : paths) {
System.out.println(path.toString());
}
assertEquals(1, paths.size());
List<Predicate<Path>> pathsToAssert = Arrays.asList(p -> p.size() == 4 && p.get(0).equals(a1) && p.get(1).equals(e1) && p.get(2).equals(b1) && p.get(3).equals(c1));
for (Predicate<Path> pathPredicate : pathsToAssert) {
Optional<Path> path = paths.stream().filter(pathPredicate).findAny();
assertTrue(path.isPresent());
assertTrue(paths.remove(path.get()));
}
assertTrue(paths.isEmpty());
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestLocalStepCompile method testLocalStepWithLimitOnDb.
// the limit is executed on the db
@Test
public void testLocalStepWithLimitOnDb() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "name", "b2");
Vertex b3 = this.sqlgGraph.addVertex(T.label, "B", "name", "b3");
Vertex c11 = this.sqlgGraph.addVertex(T.label, "C", "name", "c11");
Vertex c12 = this.sqlgGraph.addVertex(T.label, "C", "name", "c12");
Vertex c13 = this.sqlgGraph.addVertex(T.label, "C", "name", "c13");
Vertex c21 = this.sqlgGraph.addVertex(T.label, "C", "name", "c21");
Vertex c22 = this.sqlgGraph.addVertex(T.label, "C", "name", "c22");
Vertex c23 = this.sqlgGraph.addVertex(T.label, "C", "name", "c23");
Vertex c31 = this.sqlgGraph.addVertex(T.label, "C", "name", "c31");
Vertex c32 = this.sqlgGraph.addVertex(T.label, "C", "name", "c32");
Vertex c33 = this.sqlgGraph.addVertex(T.label, "C", "name", "c33");
a1.addEdge("ab", b1);
a1.addEdge("ab", b2);
a1.addEdge("ab", b3);
b1.addEdge("bc", c11);
b1.addEdge("bc", c12);
b1.addEdge("bc", c13);
b2.addEdge("bc", c21);
b2.addEdge("bc", c22);
b2.addEdge("bc", c23);
b3.addEdge("bc", c31);
b3.addEdge("bc", c32);
b3.addEdge("bc", c33);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V(a1).local(__.out().limit(1).out());
List<Vertex> vertices = traversal.toList();
Assert.assertEquals(3, vertices.size());
}
Aggregations