Search in sources :

Example 6 with ReplacedStep

use of org.umlg.sqlg.sql.parse.ReplacedStep 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());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) ReplacedStep(org.umlg.sqlg.sql.parse.ReplacedStep) SqlgGraphStep(org.umlg.sqlg.step.SqlgGraphStep) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 7 with ReplacedStep

use of org.umlg.sqlg.sql.parse.ReplacedStep in project sqlg by pietermartin.

the class TestHasLabelAndId method testConsecutiveEqHasNeqIdAndLabels.

@Test
public void testConsecutiveEqHasNeqIdAndLabels() {
    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", "D").has(T.id, P.neq(b.id()));
    List<Vertex> vertices = traversal.toList();
    Assert.assertEquals(4, vertices.size());
    Assert.assertTrue(vertices.contains(a) && vertices.contains(b2) && vertices.contains(c) && vertices.contains(d));
    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);
    // without's labels are merged into the previous labelHasContainers
    // this is because without has 'or' logic rather than 'and'
    Assert.assertEquals(1, replacedStep.getLabelHasContainers().size());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) ReplacedStep(org.umlg.sqlg.sql.parse.ReplacedStep) SqlgGraphStep(org.umlg.sqlg.step.SqlgGraphStep) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 8 with ReplacedStep

use of org.umlg.sqlg.sql.parse.ReplacedStep in project sqlg by pietermartin.

the class TestHasLabelAndId method testInWithHasLabelAndHasId2.

@Test
public void testInWithHasLabelAndHasId2() {
    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").hasId(b.id());
    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(2, replacedStep.getLabelHasContainers().size());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) ReplacedStep(org.umlg.sqlg.sql.parse.ReplacedStep) SqlgGraphStep(org.umlg.sqlg.step.SqlgGraphStep) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 9 with ReplacedStep

use of org.umlg.sqlg.sql.parse.ReplacedStep in project sqlg by pietermartin.

the class TestHasLabelAndId method testOutWithHasLabelAndHasWithoutNeqId.

@Test
public void testOutWithHasLabelAndHasWithoutNeqId() {
    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", "C", "D").has(T.id, P.neq(c.id()));
    List<Vertex> vertices = traversal.toList();
    Assert.assertEquals(3, vertices.size());
    Assert.assertTrue(vertices.contains(b) && vertices.contains(b2) && vertices.contains(d));
    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);
    // without gets merged into previous labelHasContainer
    Assert.assertEquals(1, replacedStep.getLabelHasContainers().size());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) ReplacedStep(org.umlg.sqlg.sql.parse.ReplacedStep) SqlgGraphStep(org.umlg.sqlg.step.SqlgGraphStep) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 10 with ReplacedStep

use of org.umlg.sqlg.sql.parse.ReplacedStep in project sqlg by pietermartin.

the class TestHasLabelAndId method testInWithHasLabelAndHasId.

@Test
public void testInWithHasLabelAndHasId() {
    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").hasId(b.id());
    List<Vertex> vertices = traversal.toList();
    Assert.assertEquals(1, vertices.size());
    Assert.assertEquals(b, 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);
    Assert.assertEquals(2, replacedStep.getLabelHasContainers().size());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) ReplacedStep(org.umlg.sqlg.sql.parse.ReplacedStep) SqlgGraphStep(org.umlg.sqlg.step.SqlgGraphStep) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Aggregations

ReplacedStep (org.umlg.sqlg.sql.parse.ReplacedStep)34 SqlgGraphStep (org.umlg.sqlg.step.SqlgGraphStep)34 DefaultGraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal)29 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)29 Test (org.junit.Test)29 BaseTest (org.umlg.sqlg.test.BaseTest)29 LoopTraversal (org.apache.tinkerpop.gremlin.process.traversal.lambda.LoopTraversal)4 ChooseStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.ChooseStep)4 LocalStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep)4 OptionalStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.OptionalStep)4 RepeatStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.RepeatStep)4 IdentityStep (org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep)4 SackValueStep (org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SackValueStep)4 TreeSideEffectStep (org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.TreeSideEffectStep)4 AbstractStep (org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep)4 ComputerAwareStep (org.apache.tinkerpop.gremlin.process.traversal.step.util.ComputerAwareStep)4 SqlgStep (org.umlg.sqlg.step.SqlgStep)4 SqlgVertexStep (org.umlg.sqlg.step.SqlgVertexStep)4 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)2 ReplacedStepTree (org.umlg.sqlg.sql.parse.ReplacedStepTree)2