use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestHasLabelAndId method testHasLabelWithWithinPredicate.
@Test
public void testHasLabelWithWithinPredicate() {
Vertex vEPerson = this.sqlgGraph.addVertex(T.label, "EnterprisePerson", "_uniqueId", "1");
Vertex vEProvider = this.sqlgGraph.addVertex(T.label, "EnterpriseProvider", "_uniqueId", "2");
Vertex vSPerson = this.sqlgGraph.addVertex(T.label, "SystemPerson", "_uniqueId", "3");
Vertex vSProvider = this.sqlgGraph.addVertex(T.label, "SystemProvider", "_uniqueId", "4");
Edge e1 = vSPerson.addEdge("euid", vEPerson);
Edge e2 = vSProvider.addEdge("euid", vEProvider);
Edge e3 = vSProvider.addEdge("primary", vSPerson);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("EnterprisePerson").has("_uniqueId", "1").in("euid").bothE("primary").otherV().hasLabel("SystemPerson", "SystemProvider").out("euid");
printTraversalForm(traversal);
List<Vertex> vertices = traversal.toList();
Assert.assertEquals(1, vertices.size());
Assert.assertEquals(vEProvider, vertices.get(0));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestHasLabelAndId method testHasCompareEq.
@Test
public void testHasCompareEq() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a");
this.sqlgGraph.addVertex(T.label, "A", "name", "b");
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> graphTraversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").has("name", "a");
Assert.assertEquals(2, graphTraversal.getSteps().size());
List<Vertex> vertices = graphTraversal.toList();
Assert.assertEquals(1, graphTraversal.getSteps().size());
Assert.assertEquals(1, vertices.size());
Assert.assertEquals(a1, vertices.get(0));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestHasLabelAndId method testConsecutiveEqHasIdAndLabels.
@Test
public void testConsecutiveEqHasIdAndLabels() {
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");
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V(a).hasLabel("B");
Assert.assertEquals(0, traversal.toList().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(2, replacedStep.getLabelHasContainers().size());
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestHasLabelAndId method testConsecutiveEqWithinHasLabels2.
@Test
public void testConsecutiveEqWithinHasLabels2() {
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");
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").has(T.label, P.within("B"));
Assert.assertEquals(0, traversal.toList().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(2, replacedStep.getLabelHasContainers().size());
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestHasLabelAndId method testOutWithHasLabelAndHasNeqId.
@Test
public void testOutWithHasLabelAndHasNeqId() {
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");
a.addEdge("ab", b);
a.addEdge("ab", b2);
a.addEdge("ac", c);
a.addEdge("ad", d);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").out().hasLabel("B").has(T.id, P.neq(b.id()));
List<Vertex> vertices = traversal.toList();
Assert.assertEquals(1, vertices.size());
Assert.assertEquals(b2, vertices.get(0));
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);
// neq merges its label with the previous labelHasContainers labels
Assert.assertEquals(1, replacedStep.getLabelHasContainers().size());
}
Aggregations