use of org.umlg.sqlg.step.SqlgGraphStep 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.umlg.sqlg.step.SqlgGraphStep 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.umlg.sqlg.step.SqlgGraphStep in project sqlg by pietermartin.
the class TestGremlinCompileChoose method testUnoptimizableChooseStep.
@Test
public void testUnoptimizableChooseStep() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B");
a1.addEdge("ab", b1);
a1.addEdge("ab", b2);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").choose(v -> v.label().equals("A"), __.out(), __.in());
Assert.assertEquals(3, traversal.getSteps().size());
List<Vertex> vertices = traversal.toList();
Assert.assertEquals(2, traversal.getSteps().size());
Assert.assertTrue(traversal.getSteps().get(0) instanceof SqlgGraphStep);
Assert.assertTrue(traversal.getSteps().get(1) instanceof SqlgChooseStepBarrier);
Assert.assertEquals(2, vertices.size());
}
use of org.umlg.sqlg.step.SqlgGraphStep in project sqlg by pietermartin.
the class TestRepeatStepGraphOut method testRepeatToSelf.
@Test
public void testRepeatToSelf() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a2");
a1.addEdge("aa", a2);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().repeat(__.out()).until(__.hasLabel("A"));
Assert.assertEquals(2, traversal.getSteps().size());
printTraversalForm(traversal);
Assert.assertEquals(2, traversal.getSteps().size());
Assert.assertTrue(traversal.getSteps().get(0) instanceof SqlgGraphStep);
Assert.assertTrue(traversal.getSteps().get(1) instanceof SqlgRepeatStepBarrier);
SqlgRepeatStepBarrier repeatStep = (SqlgRepeatStepBarrier) traversal.getSteps().get(1);
DefaultGraphTraversal traversal1 = (DefaultGraphTraversal) repeatStep.getGlobalChildren().get(0);
Assert.assertEquals(2, traversal1.getSteps().size());
Assert.assertTrue(traversal1.getSteps().get(0) instanceof SqlgVertexStep);
List<Vertex> vertices = traversal.toList();
Assert.assertEquals(1, vertices.size());
}
use of org.umlg.sqlg.step.SqlgGraphStep in project sqlg by pietermartin.
the class TestHasLabelAndId method testConsecutiveEqHasIdAndLabels5.
@Test
public void testConsecutiveEqHasIdAndLabels5() {
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");
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A", "B", "C").hasId(b.id()).hasId(a.id());
List<Vertex> vertices = traversal.toList();
Assert.assertEquals(0, 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(1, sqlgGraphStep.getReplacedSteps().size());
ReplacedStep replacedStep = (ReplacedStep) sqlgGraphStep.getReplacedSteps().get(0);
Assert.assertEquals(3, replacedStep.getLabelHasContainers().size());
}
Aggregations