org.umlg.sqlg.test.gremlincompile.TestGremlinCompileWithHas Maven / Gradle / Ivy
package org.umlg.sqlg.test.gremlincompile;
import org.apache.commons.collections4.set.ListOrderedSet;
import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.process.traversal.Pop;
import org.apache.tinkerpop.gremlin.process.traversal.Scope;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.MapHelper;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.umlg.sqlg.structure.*;
import org.umlg.sqlg.test.BaseTest;
import java.util.*;
import java.util.stream.Collectors;
/**
* Date: 2015/01/19
* Time: 6:22 AM
*/
public class TestGremlinCompileWithHas extends BaseTest {
@BeforeClass
public static void beforeClass() {
BaseTest.beforeClass();
if (isPostgres()) {
configuration.addProperty("distributed", true);
}
}
@Test
public void testMultipleHasWithinUserSuppliedIds() {
this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist(
"TestHierarchy",
new LinkedHashMap() {{
put("column1", PropertyType.varChar(100));
put("column2", PropertyType.varChar(100));
put("name", PropertyType.STRING);
}},
ListOrderedSet.listOrderedSet(Arrays.asList("column1", "column2"))
);
this.sqlgGraph.tx().commit();
this.sqlgGraph.addVertex(T.label, "TestHierarchy", "column1", "a1", "column2", "a2", "name", "name1");
this.sqlgGraph.addVertex(T.label, "TestHierarchy", "column1", "b1", "column2", "b2", "name", "name1");
this.sqlgGraph.addVertex(T.label, "TestHierarchy", "column1", "c1", "column2", "c2", "name", "name1");
this.sqlgGraph.addVertex(T.label, "TestHierarchy", "column1", "d1", "column2", "d2", "name", "name1");
this.sqlgGraph.tx().commit();
List values1 = Collections.singletonList("");
List values2 = Collections.singletonList("");
List vertexList = this.sqlgGraph.traversal().V()
.hasLabel("TestHierarchy")
.has("column1", P.within(values1))
.has("column2", P.within(values2))
.toList();
Assert.assertEquals(0, vertexList.size());
values1 = Arrays.asList("a1", "b1", "c1");
values2 = Arrays.asList("a2", "b2", "c2");
vertexList = this.sqlgGraph.traversal().V()
.hasLabel("TestHierarchy")
.has("column1", P.within(values1))
.has("column2", P.within(values2))
.toList();
Assert.assertEquals(3, vertexList.size());
values1 = Arrays.asList("a1");
values2 = Arrays.asList("a2", "b2", "c2");
vertexList = this.sqlgGraph.traversal().V()
.hasLabel("TestHierarchy")
.has("column1", P.within(values1))
.has("column2", P.within(values2))
.toList();
Assert.assertEquals(1, vertexList.size());
}
@Test
public void testHasPropertyWithLabel() {
this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
this.sqlgGraph.addVertex(T.label, "A", "name", "a2");
this.sqlgGraph.addVertex(T.label, "A");
this.sqlgGraph.addVertex(T.label, "A");
this.sqlgGraph.tx().commit();
List vertices = this.sqlgGraph.traversal().V().hasLabel("A").has("name").as("a").select("a").toList();
Assert.assertEquals(2, vertices.size());
vertices = this.sqlgGraph.traversal().V().hasLabel("A").hasNot("name").as("a").select("a").toList();
Assert.assertEquals(2, vertices.size());
}
@Test
public void testHasIdRecompilation() throws InterruptedException {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
this.sqlgGraph.addVertex(T.label, "A");
this.sqlgGraph.addVertex(T.label, "A");
this.sqlgGraph.tx().commit();
testHasIdRecompilation_assert(this.sqlgGraph, a1);
if (this.sqlgGraph1 != null) {
Thread.sleep(SLEEP_TIME);
testHasIdRecompilation_assert(this.sqlgGraph1, a1);
}
}
private void testHasIdRecompilation_assert(SqlgGraph sqlgGraph, Vertex a1) {
DefaultGraphTraversal gt1 = (DefaultGraphTraversal) sqlgGraph.traversal().V(a1.id());
Assert.assertEquals(1, gt1.getSteps().size());
DefaultGraphTraversal gt2 = (DefaultGraphTraversal) sqlgGraph.traversal().V().hasId(a1.id());
Assert.assertEquals(2, gt2.getSteps().size());
List vertices1 = gt1.toList();
Assert.assertEquals(1, gt1.getSteps().size());
Assert.assertEquals(1, vertices1.size());
Assert.assertEquals(a1, vertices1.get(0));
List vertices2 = gt2.toList();
Assert.assertEquals(1, gt2.getSteps().size());
Assert.assertEquals(1, vertices2.size());
Assert.assertEquals(a1, vertices2.get(0));
Assert.assertEquals(gt1, gt2);
}
@Test
public void testHasIdIn() throws InterruptedException {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
this.sqlgGraph.addVertex(T.label, "A");
this.sqlgGraph.addVertex(T.label, "A");
this.sqlgGraph.addVertex(T.label, "A");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B");
Vertex b3 = this.sqlgGraph.addVertex(T.label, "B");
Vertex b4 = this.sqlgGraph.addVertex(T.label, "B");
Vertex c1 = this.sqlgGraph.addVertex(T.label, "C");
Vertex c2 = this.sqlgGraph.addVertex(T.label, "C");
Vertex c3 = this.sqlgGraph.addVertex(T.label, "C");
Vertex c4 = this.sqlgGraph.addVertex(T.label, "C");
b1.addEdge("ab", a1);
b2.addEdge("ab", a1);
b3.addEdge("ab", a1);
b4.addEdge("ab", a1);
c1.addEdge("ac", a1);
c2.addEdge("ac", a1);
c3.addEdge("ac", a1);
c4.addEdge("ac", a1);
this.sqlgGraph.tx().commit();
testHasIdIn_assert(this.sqlgGraph);
if (this.sqlgGraph1 != null) {
Thread.sleep(SLEEP_TIME);
testHasIdIn_assert(this.sqlgGraph1);
}
}
private void testHasIdIn_assert(SqlgGraph sqlgGraph) {
long start = sqlgGraph.getSqlDialect().getPrimaryKeyStartValue();
RecordId recordIda1 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "A"), start);
RecordId recordIda2 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "A"), start + 1L);
RecordId recordIda3 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "A"), start + 2L);
RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "A"), start + 3L);
RecordId recordIdb1 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "B"), start);
RecordId recordIdb2 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "B"), start + 1L);
RecordId recordIdb3 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "B"), start + 2L);
RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "B"), start + 3L);
RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "C"), start);
RecordId recordIdc2 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "C"), start + 1L);
RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "C"), start + 2L);
RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "C"), start + 3L);
DefaultGraphTraversal traversal = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1).hasLabel("A");
Assert.assertEquals(2, traversal.getSteps().size());
List vertices = traversal.toList();
Assert.assertEquals(1, traversal.getSteps().size());
Assert.assertEquals(1, vertices.size());
DefaultGraphTraversal traversal1 = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1).has(T.id, P.within(recordIda2, recordIdb1));
Assert.assertEquals(2, traversal1.getSteps().size());
vertices = traversal1.toList();
Assert.assertEquals(1, traversal1.getSteps().size());
Assert.assertEquals(0, vertices.size());
DefaultGraphTraversal traversal2 = (DefaultGraphTraversal) sqlgGraph.traversal().V().has(T.id, P.within(recordIda1, recordIda2, recordIdb1));
Assert.assertEquals(2, traversal2.getSteps().size());
vertices = traversal2.toList();
Assert.assertEquals(1, traversal2.getSteps().size());
Assert.assertEquals(3, vertices.size());
DefaultGraphTraversal traversal3 = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1, recordIda2, recordIda3, recordIdb1);
Assert.assertEquals(1, traversal3.getSteps().size());
vertices = traversal3.toList();
Assert.assertEquals(1, traversal3.getSteps().size());
Assert.assertEquals(4, vertices.size());
DefaultGraphTraversal traversal4 = (DefaultGraphTraversal) sqlgGraph.traversal().V().has(T.id, P.within(recordIda1));
Assert.assertEquals(2, traversal4.getSteps().size());
vertices = traversal4.toList();
Assert.assertEquals(1, traversal4.getSteps().size());
Assert.assertEquals(1, vertices.size());
DefaultGraphTraversal traversal5 = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1).in().hasId(recordIdb1);
Assert.assertEquals(3, traversal5.getSteps().size());
vertices = traversal5.toList();
Assert.assertEquals(1, traversal5.getSteps().size());
Assert.assertEquals(1, vertices.size());
DefaultGraphTraversal traversal6 = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1, recordIda2, recordIda3).in().hasId(recordIdb1, recordIdb2, recordIdb3);
Assert.assertEquals(3, traversal6.getSteps().size());
vertices = traversal6.toList();
Assert.assertEquals(1, traversal6.getSteps().size());
Assert.assertEquals(3, vertices.size());
DefaultGraphTraversal traversal7 = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1).in().hasId(recordIda1);
Assert.assertEquals(3, traversal7.getSteps().size());
vertices = traversal7.toList();
Assert.assertEquals(1, traversal7.getSteps().size());
Assert.assertEquals(0, vertices.size());
DefaultGraphTraversal traversal8 = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1).in().hasId(recordIdb1);
Assert.assertEquals(3, traversal8.getSteps().size());
vertices = traversal8.toList();
Assert.assertEquals(1, traversal8.getSteps().size());
Assert.assertEquals(1, vertices.size());
DefaultGraphTraversal traversal9 = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1).in().hasId(recordIdb1, recordIdb2);
Assert.assertEquals(3, traversal9.getSteps().size());
vertices = traversal9.toList();
Assert.assertEquals(1, traversal9.getSteps().size());
Assert.assertEquals(2, vertices.size());
DefaultGraphTraversal traversal10 = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1).in().hasId(recordIdb1.toString());
Assert.assertEquals(3, traversal10.getSteps().size());
vertices = traversal10.toList();
Assert.assertEquals(1, traversal10.getSteps().size());
Assert.assertEquals(1, vertices.size());
DefaultGraphTraversal traversal11 = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1).in().hasId(recordIdb1.toString(), recordIdb2.toString());
Assert.assertEquals(3, traversal11.getSteps().size());
vertices = traversal11.toList();
Assert.assertEquals(1, traversal11.getSteps().size());
Assert.assertEquals(2, vertices.size());
DefaultGraphTraversal traversal12 = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1).in().hasId(recordIdb1.toString(), recordIdc2.toString());
Assert.assertEquals(3, traversal12.getSteps().size());
vertices = traversal12.toList();
Assert.assertEquals(1, traversal12.getSteps().size());
Assert.assertEquals(2, vertices.size());
}
@Test
public void testHasIdInJoin() throws InterruptedException {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A");
Vertex a3 = this.sqlgGraph.addVertex(T.label, "A");
Vertex a4 = this.sqlgGraph.addVertex(T.label, "A");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B");
Vertex b3 = this.sqlgGraph.addVertex(T.label, "B");
Vertex b4 = this.sqlgGraph.addVertex(T.label, "B");
Vertex c1 = this.sqlgGraph.addVertex(T.label, "C");
Vertex c2 = this.sqlgGraph.addVertex(T.label, "C");
Vertex c3 = this.sqlgGraph.addVertex(T.label, "C");
Vertex c4 = this.sqlgGraph.addVertex(T.label, "C");
Vertex d1 = this.sqlgGraph.addVertex(T.label, "D");
Vertex d2 = this.sqlgGraph.addVertex(T.label, "D");
Vertex d3 = this.sqlgGraph.addVertex(T.label, "D");
Vertex d4 = this.sqlgGraph.addVertex(T.label, "D");
b1.addEdge("ab", a1);
b2.addEdge("ab", a2);
b3.addEdge("ab", a3);
b4.addEdge("ab", a4);
c1.addEdge("ac", b1);
c1.addEdge("ac", b2);
c1.addEdge("ac", b3);
c1.addEdge("ac", b4);
d1.addEdge("ac", c1);
d2.addEdge("ac", c2);
d3.addEdge("ac", c3);
d4.addEdge("ac", c4);
this.sqlgGraph.tx().commit();
testHasIdInJoin_assert(this.sqlgGraph, a1, a2, a3, a4);
if (this.sqlgGraph1 != null) {
Thread.sleep(SLEEP_TIME);
testHasIdInJoin_assert(this.sqlgGraph, a1, a2, a3, a4);
}
}
private void testHasIdInJoin_assert(SqlgGraph sqlgGraph, Vertex a1, Vertex a2, Vertex a3, Vertex a4) {
long start = sqlgGraph.getSqlDialect().getPrimaryKeyStartValue();
RecordId recordIda1 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "A"), start);
RecordId recordIda2 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "A"), start + 1L);
RecordId recordIda3 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "A"), start + 2L);
RecordId recordIda4 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "A"), start + 3L);
RecordId recordIdb1 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "B"), start);
RecordId recordIdb2 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "B"), start + 1L);
RecordId recordIdb3 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "B"), start + 2L);
RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "B"), start + 3L);
RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "C"), start);
RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "C"), start + 1L);
RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "C"), start + 2L);
RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "C"), start + 3L);
DefaultGraphTraversal traversal = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1, recordIda2, recordIda3, recordIda4).in().hasId(recordIdb1, recordIdb2, recordIdb3);
Assert.assertEquals(3, traversal.getSteps().size());
List vertices = traversal.toList();
Assert.assertEquals(1, traversal.getSteps().size());
Assert.assertEquals(3, vertices.size());
DefaultGraphTraversal traversal1 = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1.toString(), recordIda2.toString(), recordIda3.toString(), recordIda4.toString()).in()
.hasId(recordIdb1.toString(), recordIdb2.toString(), recordIdb3.toString());
Assert.assertEquals(3, traversal1.getSteps().size());
vertices = traversal1.toList();
Assert.assertEquals(1, traversal1.getSteps().size());
Assert.assertEquals(3, vertices.size());
DefaultGraphTraversal traversal2 = (DefaultGraphTraversal) sqlgGraph.traversal().V(a1, a2, a3, a4).in()
.hasId(recordIdb1.toString(), recordIdb2.toString(), recordIdb3.toString());
Assert.assertEquals(3, traversal2.getSteps().size());
vertices = traversal2.toList();
Assert.assertEquals(1, traversal2.getSteps().size());
Assert.assertEquals(3, vertices.size());
DefaultGraphTraversal traversal3 = (DefaultGraphTraversal) sqlgGraph.traversal().V(a1, a2, a3, a4).in()
.hasId(recordIdb1.toString(), recordIdb2.toString(), recordIdb3.toString());
Assert.assertEquals(3, traversal3.getSteps().size());
vertices = traversal3.toList();
Assert.assertEquals(1, traversal3.getSteps().size());
Assert.assertEquals(3, vertices.size());
}
@Test
public void testHasIdOutJoin() throws InterruptedException {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A");
Vertex a3 = this.sqlgGraph.addVertex(T.label, "A");
Vertex a4 = this.sqlgGraph.addVertex(T.label, "A");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B");
Vertex b3 = this.sqlgGraph.addVertex(T.label, "B");
Vertex b4 = this.sqlgGraph.addVertex(T.label, "B");
Vertex c1 = this.sqlgGraph.addVertex(T.label, "C");
Vertex c2 = this.sqlgGraph.addVertex(T.label, "C");
Vertex c3 = this.sqlgGraph.addVertex(T.label, "C");
Vertex c4 = this.sqlgGraph.addVertex(T.label, "C");
Vertex d1 = this.sqlgGraph.addVertex(T.label, "D");
Vertex d2 = this.sqlgGraph.addVertex(T.label, "D");
Vertex d3 = this.sqlgGraph.addVertex(T.label, "D");
Vertex d4 = this.sqlgGraph.addVertex(T.label, "D");
a1.addEdge("ab", b1);
a2.addEdge("ab", b2);
a3.addEdge("ab", b3);
a4.addEdge("ab", b4);
a1.addEdge("ac", c1);
a1.addEdge("ac", c2);
a1.addEdge("ac", c3);
a1.addEdge("ac", c4);
c1.addEdge("ac", d1);
c2.addEdge("ac", d2);
c3.addEdge("ac", d3);
c4.addEdge("ac", d4);
this.sqlgGraph.tx().commit();
testHasIdOutJoin_assert(this.sqlgGraph, a1, a2, a3, a4);
if (this.sqlgGraph1 != null) {
Thread.sleep(SLEEP_TIME);
testHasIdOutJoin_assert(this.sqlgGraph1, a1, a2, a3, a4);
}
}
private void testHasIdOutJoin_assert(SqlgGraph sqlgGraph, Vertex a1, Vertex a2, Vertex a3, Vertex a4) {
long start = sqlgGraph.getSqlDialect().getPrimaryKeyStartValue();
RecordId recordIda1 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "A"), start);
RecordId recordIda2 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "A"), start + 1L);
RecordId recordIda3 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "A"), start + 2L);
RecordId recordIda4 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "A"), start + 3L);
RecordId recordIdb1 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "B"), start);
RecordId recordIdb2 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "B"), start + 1L);
RecordId recordIdb3 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "B"), start + 2L);
RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "B"), start + 3L);
RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "C"), start);
RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "C"), start + 1L);
RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "C"), start + 2L);
RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "C"), start + 3L);
DefaultGraphTraversal traversal = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1, recordIda2, recordIda3, recordIda4).out().hasId(recordIdb1, recordIdb2, recordIdb3);
Assert.assertEquals(3, traversal.getSteps().size());
List vertices = traversal.toList();
Assert.assertEquals(1, traversal.getSteps().size());
Assert.assertEquals(3, vertices.size());
DefaultGraphTraversal traversal1 = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1.toString(), recordIda2.toString(), recordIda3.toString(), recordIda4.toString()).out()
.hasId(recordIdb1.toString(), recordIdb2.toString(), recordIdb3.toString());
Assert.assertEquals(3, traversal1.getSteps().size());
vertices = traversal1.toList();
Assert.assertEquals(1, traversal1.getSteps().size());
Assert.assertEquals(3, vertices.size());
DefaultGraphTraversal traversal2 = (DefaultGraphTraversal) sqlgGraph.traversal().V(a1, a2, a3, a4).out()
.hasId(recordIdb1.toString(), recordIdb2.toString(), recordIdb3.toString());
Assert.assertEquals(3, traversal2.getSteps().size());
vertices = traversal2.toList();
Assert.assertEquals(1, traversal2.getSteps().size());
Assert.assertEquals(3, vertices.size());
DefaultGraphTraversal traversal3 = (DefaultGraphTraversal) sqlgGraph.traversal().V(a1, a2, a3, a4).out()
.hasId(recordIdb1.toString(), recordIdb2.toString(), recordIdb3.toString());
Assert.assertEquals(3, traversal3.getSteps().size());
vertices = traversal3.toList();
Assert.assertEquals(1, traversal3.getSteps().size());
Assert.assertEquals(3, vertices.size());
}
@Test
public void testHasIdOut() throws InterruptedException {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
this.sqlgGraph.addVertex(T.label, "A");
this.sqlgGraph.addVertex(T.label, "A");
this.sqlgGraph.addVertex(T.label, "A");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B");
Vertex b3 = this.sqlgGraph.addVertex(T.label, "B");
Vertex b4 = this.sqlgGraph.addVertex(T.label, "B");
Vertex c1 = this.sqlgGraph.addVertex(T.label, "C");
Vertex c2 = this.sqlgGraph.addVertex(T.label, "C");
Vertex c3 = this.sqlgGraph.addVertex(T.label, "C");
Vertex c4 = this.sqlgGraph.addVertex(T.label, "C");
a1.addEdge("ab", b1);
a1.addEdge("ab", b2);
a1.addEdge("ab", b3);
a1.addEdge("ab", b4);
a1.addEdge("ac", c1);
a1.addEdge("ac", c2);
a1.addEdge("ac", c3);
a1.addEdge("ac", c4);
this.sqlgGraph.tx().commit();
testHasIdOut_assert(this.sqlgGraph);
if (this.sqlgGraph1 != null) {
Thread.sleep(SLEEP_TIME);
testHasIdOut_assert(this.sqlgGraph1);
}
}
private void testHasIdOut_assert(SqlgGraph sqlgGraph) {
long start = sqlgGraph.getSqlDialect().getPrimaryKeyStartValue();
RecordId recordIda1 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "A"), start);
RecordId recordIda2 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "A"), start + 1L);
RecordId recordIda3 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "A"), start + 2L);
RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "A"), start + 3L);
RecordId recordIdb1 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "B"), start);
RecordId recordIdb2 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "B"), start + 1L);
RecordId recordIdb3 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "B"), start + 2L);
RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "B"), start + 3L);
RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "C"), start);
RecordId recordIdc2 = RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "C"), start + 1L);
RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "C"), start + 2L);
RecordId.from(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "C"), start + 3L);
DefaultGraphTraversal traversal = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1).hasLabel("A");
Assert.assertEquals(2, traversal.getSteps().size());
List vertices = traversal.toList();
Assert.assertEquals(1, traversal.getSteps().size());
Assert.assertEquals(1, vertices.size());
DefaultGraphTraversal traversal1 = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1).has(T.id, P.within(recordIda2, recordIdb1));
Assert.assertEquals(2, traversal1.getSteps().size());
vertices = traversal1.toList();
Assert.assertEquals(1, traversal1.getSteps().size());
Assert.assertEquals(0, vertices.size());
DefaultGraphTraversal traversal2 = (DefaultGraphTraversal) sqlgGraph.traversal().V().has(T.id, P.within(recordIda1, recordIda2, recordIdb1));
Assert.assertEquals(2, traversal2.getSteps().size());
vertices = traversal2.toList();
Assert.assertEquals(1, traversal2.getSteps().size());
Assert.assertEquals(3, vertices.size());
DefaultGraphTraversal traversal3 = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1, recordIda2, recordIda3, recordIdb1);
Assert.assertEquals(1, traversal3.getSteps().size());
vertices = traversal3.toList();
Assert.assertEquals(1, traversal3.getSteps().size());
Assert.assertEquals(4, vertices.size());
DefaultGraphTraversal traversal4 = (DefaultGraphTraversal) sqlgGraph.traversal().V().has(T.id, P.within(recordIda1));
Assert.assertEquals(2, traversal4.getSteps().size());
vertices = traversal4.toList();
Assert.assertEquals(1, traversal4.getSteps().size());
Assert.assertEquals(1, vertices.size());
DefaultGraphTraversal traversal5 = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1).out().hasId(recordIdb1);
Assert.assertEquals(3, traversal5.getSteps().size());
vertices = traversal5.toList();
Assert.assertEquals(1, traversal5.getSteps().size());
Assert.assertEquals(1, vertices.size());
DefaultGraphTraversal traversal6 = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1, recordIda2, recordIda3).out().hasId(recordIdb1, recordIdb2, recordIdb3);
Assert.assertEquals(3, traversal6.getSteps().size());
vertices = traversal6.toList();
Assert.assertEquals(1, traversal6.getSteps().size());
Assert.assertEquals(3, vertices.size());
DefaultGraphTraversal traversal7 = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1).out().hasId(recordIda1);
Assert.assertEquals(3, traversal7.getSteps().size());
vertices = traversal7.toList();
Assert.assertEquals(1, traversal7.getSteps().size());
Assert.assertEquals(0, vertices.size());
DefaultGraphTraversal traversal8 = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1).out().hasId(recordIdb1);
Assert.assertEquals(3, traversal8.getSteps().size());
vertices = traversal8.toList();
Assert.assertEquals(1, traversal8.getSteps().size());
Assert.assertEquals(1, vertices.size());
DefaultGraphTraversal traversal9 = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1).out().hasId(recordIdb1, recordIdb2);
Assert.assertEquals(3, traversal9.getSteps().size());
vertices = traversal9.toList();
Assert.assertEquals(1, traversal9.getSteps().size());
Assert.assertEquals(2, vertices.size());
DefaultGraphTraversal traversal10 = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1).out().hasId(recordIdb1.toString());
Assert.assertEquals(3, traversal10.getSteps().size());
vertices = traversal10.toList();
Assert.assertEquals(1, traversal10.getSteps().size());
Assert.assertEquals(1, vertices.size());
DefaultGraphTraversal traversal11 = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1).out().hasId(recordIdb1.toString(), recordIdb2.toString());
Assert.assertEquals(3, traversal11.getSteps().size());
vertices = traversal11.toList();
Assert.assertEquals(1, traversal11.getSteps().size());
Assert.assertEquals(2, vertices.size());
DefaultGraphTraversal traversal12 = (DefaultGraphTraversal) sqlgGraph.traversal().V(recordIda1).out().hasId(recordIdb1.toString(), recordIdc2.toString());
Assert.assertEquals(3, traversal12.getSteps().size());
vertices = traversal12.toList();
Assert.assertEquals(1, traversal12.getSteps().size());
Assert.assertEquals(2, vertices.size());
}
@Test
public void g_V_asXaX_out_asXbX_selectXa_bX_byXnameX() {
Graph g = this.sqlgGraph;
loadModern(this.sqlgGraph);
assertModernGraph(g, true, false);
DefaultGraphTraversal> traversal = (DefaultGraphTraversal>) g.traversal()
.V().as("a").out().aggregate("x").as("b").select("a", "b").by("name");
Assert.assertEquals(4, traversal.getSteps().size());
printTraversalForm(traversal);
Assert.assertEquals(3, traversal.getSteps().size());
final List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy