You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by co...@apache.org on 2025/09/05 22:22:25 UTC
(tinkerpop) 16/19: Troubleshooting graph computer.
This is an automated email from the ASF dual-hosted git repository.
colegreer pushed a commit to branch repeatLimit
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 96882afcab0afad5885e0981f25ee730f2e4ee44
Author: Andrea Child <an...@improving.com>
AuthorDate: Wed Sep 3 17:20:28 2025 -0700
Troubleshooting graph computer.
---
.../process/traversal/step/branch/RepeatStep.java | 11 +-
.../traversal/step/filter/RangeGlobalStep.java | 31 ++-
.../process/traversal/step/map/VertexStep.java | 9 +-
.../tinkergraph/structure/TinkerGraphPlayTest.java | 269 ++++++++++-----------
4 files changed, 160 insertions(+), 160 deletions(-)
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatStep.java
index 0c6ef0fd0d..97533940df 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatStep.java
@@ -264,19 +264,22 @@ public final class RepeatStep<S> extends ComputerAwareStep<S, S> implements Trav
throw new IllegalStateException("The repeat()-traversal was not defined: " + this);
final Traverser.Admin<S> start = this.starts.next();
+ System.out.printf("RepeatStep.computerAlgorithm: received traverser%n");
if (doUntil(start, true)) {
+ System.out.printf("RepeatStep.computerAlgorithm: doUntil=true, exiting%n");
start.setStepId(this.getNextStep().getId());
start.addLabels(this.labels);
return IteratorUtils.of(start);
} else {
+ System.out.printf("RepeatStep.computerAlgorithm: entering repeat body%n");
start.setStepId(this.repeatTraversal.getStartStep().getId());
String ln;
if (this.loopName != null) {
ln = this.loopName;
} else {
- ln = start.getStepId();
+ ln = this.getId();
}
- start.initialiseLoops(start.getStepId(), ln);
+ start.initialiseLoops(this.getId(), ln);
if (doEmit(start, true)) {
final Traverser.Admin<S> emitSplit = start.split();
emitSplit.resetLoops();
@@ -368,8 +371,11 @@ public final class RepeatStep<S> extends ComputerAwareStep<S, S> implements Trav
protected Iterator<Traverser.Admin<S>> computerAlgorithm() throws NoSuchElementException {
final RepeatStep<S> repeatStep = (RepeatStep<S>) this.getTraversal().getParent();
final Traverser.Admin<S> start = this.starts.next();
+ System.out.printf("RepeatEndStep.computerAlgorithm: %s loops=%d before incrLoops%n", start.path(), start.loops());
start.incrLoops();
+ System.out.printf("RepeatEndStep.computerAlgorithm: %s loops=%d after incrLoops%n", start.path(), start.loops());
if (repeatStep.doUntil(start, false)) {
+ System.out.printf("RepeatEndStep.computerAlgorithm: doUntil=true, calling resetLoops for %s%n", start.path());
start.resetLoops();
start.setStepId(repeatStep.getNextStep().getId());
start.addLabels(repeatStep.labels);
@@ -378,6 +384,7 @@ public final class RepeatStep<S> extends ComputerAwareStep<S, S> implements Trav
start.setStepId(repeatStep.getId());
if (repeatStep.doEmit(start, false)) {
final Traverser.Admin<S> emitSplit = start.split();
+ System.out.printf("RepeatEndStep.computerAlgorithm: doEmit=true, calling resetLoops for emitSplit %s%n", emitSplit.path());
emitSplit.resetLoops();
emitSplit.setStepId(repeatStep.getNextStep().getId());
emitSplit.addLabels(repeatStep.labels);
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/RangeGlobalStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/RangeGlobalStep.java
index b1c61905ea..50ea137f20 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/RangeGlobalStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/RangeGlobalStep.java
@@ -68,35 +68,40 @@ public final class RangeGlobalStep<S> extends FilterStep<S> implements Ranging,
@Override
protected boolean filter(final Traverser.Admin<S> traverser) {
+ System.out.printf("Filter called: %s loops=%d%n", traverser.path(), traverser.loops());
if (this.bypass) return true;
// Determine which counter to use
AtomicLong currentCounter = this.counter;
if (usePerIterationCounters) {
- StringBuilder sb = new StringBuilder();
+ // Find the parent repeat step and use its loop context
+ String repeatStepId = null;
+ int repeatLoops = 0;
+
Traversal.Admin<?,?> t = this.traversal;
while (!t.isRoot()) {
TraversalParent pt = t.getParent();
Step<?, ?> ps = pt.asStep();
- String pid = ps.getId();
- if (traverser.getLoopNames().contains(pid)) {
- sb.append(pid).append(":");
- sb.append(traverser.loops(pid)).append(":");
+ if (ps.getClass().getSimpleName().equals("RepeatStep")) {
+ repeatStepId = ps.getId();
+ if (traverser.getLoopNames().contains(repeatStepId)) {
+ repeatLoops = traverser.loops(repeatStepId);
+ }
+ break;
}
t = ps.getTraversal();
}
- sb.append(this.getId()).append(":").append(traverser.loops());
-
- // Create counter key that isolates between different repeat step contexts
- String iterationKey = sb.toString();
-// Object vId = ((Vertex) traverser.get()).property("id").value();
+
+ // Create key based on repeat step and its current iteration
+ String iterationKey = repeatStepId + ":" + repeatLoops;
currentCounter = perIterationCounters.computeIfAbsent(iterationKey, k -> new AtomicLong(0L));
- // System.out.printf("IterationKey: %s Traverser: %s Path: %s Counter: %s High: %s%n", iterationKey, vId, traverser.path(), currentCounter.get(), this.high);
+ System.out.printf("IterationKey: %s RepeatLoops: %d Counter: %d Path: %s%n", iterationKey, repeatLoops, currentCounter.get(), traverser.path());
}
+ System.out.printf("Traverser: %s%n", traverser);
if (this.high != -1 && currentCounter.get() >= this.high) {
if (usePerIterationCounters) {
- // System.out.printf("Filter false for Traverser: %s Counter: %d%n", traverser.path(), currentCounter.get());
+ System.out.printf("Filter false for Traverser: %s Counter: %d%n", traverser.path(), currentCounter.get());
return false;
}
// System.out.printf("FastNoSuchElementException for Traverser: %s Counter: %d%n", traverser.path(), currentCounter.get());
@@ -233,7 +238,9 @@ public final class RangeGlobalStep<S> extends FilterStep<S> implements Ranging,
@Override
public void addBarrier(final TraverserSet<S> barrier) {
+ System.out.printf("=== addBarrier called with %d traversers ===%n", barrier.size());
IteratorUtils.removeOnNext(barrier.iterator()).forEachRemaining(traverser -> {
+ System.out.printf("Barrier traverser: %s loops=%d%n", traverser.path(), traverser.loops());
traverser.setSideEffects(this.getTraversal().getSideEffects());
this.addStart(traverser);
});
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/VertexStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/VertexStep.java
index f4d2743f24..f23d17e8cf 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/VertexStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/VertexStep.java
@@ -70,9 +70,16 @@ public class VertexStep<E extends Element> extends FlatMapStep<Vertex, E> implem
@Override
protected Iterator<E> flatMap(final Traverser.Admin<Vertex> traverser) {
- return Vertex.class.isAssignableFrom(this.returnClass) ?
+ Iterator<E> result = Vertex.class.isAssignableFrom(this.returnClass) ?
(Iterator<E>) traverser.get().vertices(this.direction, this.edgeLabels) :
(Iterator<E>) traverser.get().edges(this.direction, this.edgeLabels);
+
+ // Count results for debugging
+ List<E> resultList = new java.util.ArrayList<>();
+ result.forEachRemaining(resultList::add);
+ System.out.printf("VertexStep.flatMap: traverser=%s direction=%s labels=%s results=%s%n",
+ traverser, this.direction, Arrays.toString(this.edgeLabels), resultList);
+ return resultList.iterator();
}
@Override
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
index 297aa4a240..594090b1e1 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
@@ -22,6 +22,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Supplier;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.tinkerpop.gremlin.process.computer.Computer;
import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.process.traversal.Path;
@@ -58,8 +59,8 @@ import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.sack;
import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.select;
import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.union;
import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.valueMap;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
/**
* @author Stephen Mallette (http://stephen.genoprime.com);
@@ -72,180 +73,165 @@ public class TinkerGraphPlayTest {
public static void setup() {
g = TinkerGraph.open().traversal().withoutStrategies(RepeatUnrollStrategy.class);
load(g);
+ g = g.withComputer(Computer.compute().workers(1));
}
@Test
public void testBasicRepeatLimit() {
- GraphTraversal<Vertex, Path> basic = g.V().has("id", "l1-0")
+ GraphTraversal<Vertex, Vertex> basic = g.V().has("id", "l1-0")
.repeat(__.limit(1).out("knows"))
- .times(2).path().by("id");
- GraphTraversal<Vertex, Path> basicUnfolded = g.V().has("id", "l1-0")
+ .times(2);
+ GraphTraversal<Vertex, Vertex> basicUnfolded = g.V().has("id", "l1-0")
.limit(1).out("knows")
- .limit(1).out("knows")
- .path().by("id");
- assertEquals(toListAndPrint("basic", basic), toListAndPrint("basicUnfolded", basicUnfolded));
+ .limit(1).out("knows");
+ assertTrue(CollectionUtils.isEqualCollection(toListAndPrint("basic", basic), toListAndPrint("basicUnfolded", basicUnfolded)));
}
@Test
public void testBasicRepeatLimitIncreasedLimit() {
- GraphTraversal<Vertex, Path> basic = g.V().has("id", "l1-0")
+ GraphTraversal<Vertex, Vertex> basic = g.V().has("id", "l1-0")
.repeat(__.limit(2).out("knows"))
- .times(2).path().by("id");
- GraphTraversal<Vertex, Path> basicUnfolded = g.V().has("id", "l1-0")
- .limit(2).out("knows")
+ .times(2);
+ GraphTraversal<Vertex, Vertex> basicUnfolded = g.V().has("id", "l1-0")
.limit(2).out("knows")
- .path().by("id");
- assertEquals(toListAndPrint("basic", basic), toListAndPrint("basicUnfolded", basicUnfolded));
+ .limit(2).out("knows");
+ assertTrue(CollectionUtils.isEqualCollection(toListAndPrint("basic", basic), toListAndPrint("basicUnfolded", basicUnfolded)));
}
@Test
public void testRepeatOutLimit() {
GraphTraversal<Vertex, Path> outLimit = g.V().has("id", "l2-0")
- .repeat(__.out("knows").limit(2))
- .times(2).path().by("id");
+ .repeat(__.out("knows").order().by("id").limit(2))
+ .times(2)
+ .path().by(T.id);
GraphTraversal<Vertex, Path> outLimitUnfolded = g.V().has("id", "l2-0")
- .out("knows").limit(2)
- .out("knows").limit(2)
- .path().by("id");
- assertEquals(toListAndPrint("outLimit", outLimit), toListAndPrint("outLimitUnfolded", outLimitUnfolded));
+ .out("knows").order().by("id").limit(2)
+ .out("knows").order().by("id").limit(2)
+ .path().by(T.id);
+ assertTrue(CollectionUtils.isEqualCollection(toListAndPrint("outLimit", outLimit), toListAndPrint("outLimitUnfolded", outLimitUnfolded)));
}
@Test
public void testRepeatWithBothAndLimit() {
- GraphTraversal<Vertex, Path> bothLimit = g.V().has("id", "l3-0")
- .repeat(__.both("knows").limit(3))
- .times(2).path().by("id");
- GraphTraversal<Vertex, Path> bothLimitUnfolded = g.V().has("id", "l3-0")
- .both("knows").limit(3)
- .both("knows").limit(3)
- .path().by("id");
- assertEquals(toListAndPrint("bothLimit", bothLimit), toListAndPrint("bothLimitUnfolded", bothLimitUnfolded));
+ GraphTraversal<Vertex, Vertex> bothLimit = g.V().has("id", "l3-0")
+ .repeat(__.both("knows").order().by("id").limit(3))
+ .times(2);
+ GraphTraversal<Vertex, Vertex> bothLimitUnfolded = g.V().has("id", "l3-0")
+ .both("knows").order().by("id").limit(3)
+ .both("knows").order().by("id").limit(3);
+ assertTrue(CollectionUtils.isEqualCollection(toListAndPrint("bothLimit", bothLimit), toListAndPrint("bothLimitUnfolded", bothLimitUnfolded)));
}
@Test
public void testRepeatWithFilterAndLimit() {
- GraphTraversal<Vertex, Path> filterLimit = g.V().has("id", "l2-0")
- .repeat(__.out("knows").has("id", P.neq("l4-3")).limit(2))
- .times(2).path().by("id");
- GraphTraversal<Vertex, Path> filterLimitUnfolded = g.V().has("id", "l2-0")
- .out("knows").has("id", P.neq("l4-3")).limit(2)
- .out("knows").has("id", P.neq("l4-3")).limit(2)
- .path().by("id");
- assertEquals(toListAndPrint("filterLimit", filterLimit), toListAndPrint("filterLimitUnfolded", filterLimitUnfolded));
+ GraphTraversal<Vertex, Vertex> filterLimit = g.V().has("id", "l2-0")
+ .repeat(__.out("knows").has("id", P.neq("l4-3")).order().limit(2))
+ .times(2);
+ GraphTraversal<Vertex, Vertex> filterLimitUnfolded = g.V().has("id", "l2-0")
+ .out("knows").has("id", P.neq("l4-3")).order().limit(2)
+ .out("knows").has("id", P.neq("l4-3")).order().limit(2);
+ assertTrue(CollectionUtils.isEqualCollection(toListAndPrint("filterLimit", filterLimit), toListAndPrint("filterLimitUnfolded", filterLimitUnfolded)));
}
@Test
public void testChainedRepeatLimit() {
- GraphTraversal<Vertex, Path> chained = g.V().has("id", "l2-0")
- .repeat(__.limit(1).out("knows")).times(2)
- .repeat(__.limit(1).in("knows")).times(2)
- .path().by("id");
- GraphTraversal<Vertex, Path> chainedUnfolded = g.V().has("id", "l2-0")
- .limit(1).out("knows")
- .limit(1).out("knows")
- .limit(1).in("knows")
- .limit(1).in("knows")
- .path().by("id");
- assertEquals(toListAndPrint("chained", chained), toListAndPrint("chainedUnfolded", chainedUnfolded));
+ GraphTraversal<Vertex, Vertex> chained = g.V().has("id", "l2-0")
+ .repeat(__.order().by("id").limit(1).out("knows")).times(2)
+ .repeat(__.order().by("id").limit(1).in("knows")).times(2);
+ GraphTraversal<Vertex, Vertex> chainedUnfolded = g.V().has("id", "l2-0")
+ .order().by("id").limit(1).out("knows")
+ .order().by("id").limit(1).out("knows")
+ .order().by("id").limit(1).in("knows")
+ .order().by("id").limit(1).in("knows");
+ assertTrue(CollectionUtils.isEqualCollection(toListAndPrint("chained", chained), toListAndPrint("chainedUnfolded", chainedUnfolded)));
}
@Test
public void testChainedRepeatLimitIncreasedLimit() {
- GraphTraversal<Vertex, Path> chained = g.V().has("id", "l2-0")
- .repeat(__.limit(2).out("knows")).times(2)
- .repeat(__.limit(3).in("knows")).times(2)
- .path().by("id");
- GraphTraversal<Vertex, Path> chainedUnfolded = g.V().has("id", "l2-0")
- .limit(2).out("knows")
- .limit(2).out("knows")
- .limit(3).in("knows")
- .limit(3).in("knows")
- .path().by("id");
- assertEquals(toListAndPrint("chained", chained), toListAndPrint("chainedUnfolded", chainedUnfolded));
+ GraphTraversal<Vertex, Vertex> chained = g.V().has("id", "l2-0")
+ .repeat(__.order().by("id").limit(2).out("knows")).times(2)
+ .repeat(__.order().by("id").limit(3).in("knows")).times(2);
+ GraphTraversal<Vertex, Vertex> chainedUnfolded = g.V().has("id", "l2-0")
+ .order().by("id").limit(2).out("knows")
+ .order().by("id").limit(2).out("knows")
+ .order().by("id").limit(3).in("knows")
+ .order().by("id").limit(3).in("knows");
+ assertTrue(CollectionUtils.isEqualCollection(toListAndPrint("chained", chained), toListAndPrint("chainedUnfolded", chainedUnfolded)));
}
@Test
public void testNestedRepeatLimit() {
- GraphTraversal<Vertex, Path> nested = g.V().has("id", "l3-0")
- .repeat(__.limit(1).out("knows")
- .repeat(__.limit(1).in("knows"))
+ GraphTraversal<Vertex, Vertex> nested = g.V().has("id", "l3-0")
+ .repeat(__.order().by("id").limit(1).out("knows")
+ .repeat(__.order().by("id").limit(1).in("knows"))
.times(2))
- .times(2)
- .path().by("id");
- GraphTraversal<Vertex, Path> nestedUnfolded = g.V().has("id", "l3-0")
- .limit(1).out("knows")
- .limit(1).in("knows")
- .limit(1).in("knows")
- .limit(1).out("knows")
- .limit(1).in("knows")
- .limit(1).in("knows")
- .path().by("id");
- assertEquals(toListAndPrint("nested", nested), toListAndPrint("nestedUnfolded", nestedUnfolded));
-
- GraphTraversal<Vertex, Path> nested2 = g.V().has("id", "l3-0").out("knows").
- repeat(__.limit(1).out("knows")
- .repeat(__.limit(1).in("knows"))
+ .times(2);
+ GraphTraversal<Vertex, Vertex> nestedUnfolded = g.V().has("id", "l3-0")
+ .order().by("id").limit(1).out("knows")
+ .order().by("id").limit(1).in("knows")
+ .order().by("id").limit(1).in("knows")
+ .order().by("id").limit(1).out("knows")
+ .order().by("id").limit(1).in("knows")
+ .order().by("id").limit(1).in("knows");
+ assertTrue(CollectionUtils.isEqualCollection(toListAndPrint("nested", nested), toListAndPrint("nestedUnfolded", nestedUnfolded)));
+
+ GraphTraversal<Vertex, Vertex> nested2 = g.V().has("id", "l3-0").out("knows").order().by("id").
+ repeat(__.order().by("id").limit(1).out("knows")
+ .repeat(__.order().by("id").limit(1).in("knows"))
.times(2)).
- times(2)
- .path().by("id");
- GraphTraversal<Vertex, Path> nested2Unfolded = g.V().has("id", "l3-0").out("knows")
- .limit(1).out("knows")
- .limit(1).in("knows")
- .limit(1).in("knows")
- .limit(1).out("knows")
- .limit(1).in("knows")
- .limit(1).in("knows")
- .path().by("id");
- assertEquals(toListAndPrint("nested2", nested2), toListAndPrint("nested2Unfolded", nested2Unfolded));
+ times(2);
+ GraphTraversal<Vertex, Vertex> nested2Unfolded = g.V().has("id", "l3-0").out("knows").order().by("id")
+ .order().by("id").limit(1).out("knows")
+ .order().by("id").limit(1).in("knows")
+ .order().by("id").limit(1).in("knows")
+ .order().by("id").limit(1).out("knows")
+ .order().by("id").limit(1).in("knows")
+ .order().by("id").limit(1).in("knows");
+ assertTrue(CollectionUtils.isEqualCollection(toListAndPrint("nested2", nested2), toListAndPrint("nested2Unfolded", nested2Unfolded)));
}
@Test
public void testNestedRepeatLimitIncreasedLimit() {
- GraphTraversal<Vertex, Path> nested = g.V().has("id", "l3-0")
- .repeat(__.limit(2).out("knows")
- .repeat(__.limit(3).in("knows"))
+ GraphTraversal<Vertex, Vertex> nested = g.V().has("id", "l3-0")
+ .repeat(__.order().by("id").limit(2).out("knows")
+ .repeat(__.order().by("id").limit(3).in("knows"))
.times(2))
- .times(2)
- .path().by("id");
- GraphTraversal<Vertex, Path> nestedUnfolded = g.V().has("id", "l3-0")
- .limit(2).out("knows")
- .limit(3).in("knows")
- .limit(3).in("knows")
- .limit(2).out("knows")
- .limit(3).in("knows")
- .limit(3).in("knows")
- .path().by("id");
- assertEquals(toListAndPrint("nested", nested), toListAndPrint("nestedUnfolded", nestedUnfolded));
-
- GraphTraversal<Vertex, Path> nested2 = g.V().has("id", "l3-0").out("knows").
- repeat(__.limit(1).out("knows")
- .repeat(__.limit(1).in("knows"))
+ .times(2);
+ GraphTraversal<Vertex, Vertex> nestedUnfolded = g.V().has("id", "l3-0")
+ .order().by("id").limit(2).out("knows")
+ .order().by("id").limit(3).in("knows")
+ .order().by("id").limit(3).in("knows")
+ .order().by("id").limit(2).out("knows")
+ .order().by("id").limit(3).in("knows")
+ .order().by("id").limit(3).in("knows");
+ assertTrue(CollectionUtils.isEqualCollection(toListAndPrint("nested", nested), toListAndPrint("nestedUnfolded", nestedUnfolded)));
+
+ GraphTraversal<Vertex, Vertex> nested2 = g.V().has("id", "l3-0").out("knows").
+ repeat(__.order().by("id").limit(1).out("knows")
+ .repeat(__.order().by("id").limit(1).in("knows"))
.times(2)).
- times(2)
- .path().by("id");
- GraphTraversal<Vertex, Path> nested2Unfolded = g.V().has("id", "l3-0").out("knows")
- .limit(1).out("knows")
- .limit(1).in("knows")
- .limit(1).in("knows")
- .limit(1).out("knows")
- .limit(1).in("knows")
- .limit(1).in("knows")
- .path().by("id");
- assertEquals(toListAndPrint("nested2", nested2), toListAndPrint("nested2Unfolded", nested2Unfolded));
+ times(2);
+ GraphTraversal<Vertex, Vertex> nested2Unfolded = g.V().has("id", "l3-0").out("knows")
+ .order().by("id").limit(1).out("knows")
+ .order().by("id").limit(1).in("knows")
+ .order().by("id").limit(1).in("knows")
+ .order().by("id").limit(1).out("knows")
+ .order().by("id").limit(1).in("knows")
+ .order().by("id").limit(1).in("knows");
+ assertTrue(CollectionUtils.isEqualCollection(toListAndPrint("nested2", nested2), toListAndPrint("nested2Unfolded", nested2Unfolded)));
}
@Test
public void testTripleNestedRepeatLimit() {
- GraphTraversal<Vertex, Path> tripleNested = g.V().has("id", "l1-0")
+ GraphTraversal<Vertex, Vertex> tripleNested = g.V().has("id", "l1-0")
.repeat(__.limit(1).out("knows")
.repeat(__.limit(1).in("knows")
.repeat(__.limit(1).out("knows"))
.times(2))
.times(2))
- .times(2)
- .path().by("id");
- GraphTraversal<Vertex, Path> tripleNestedUnfolded = g.V().has("id", "l1-0")
+ .times(2);
+ GraphTraversal<Vertex, Vertex> tripleNestedUnfolded = g.V().has("id", "l1-0")
.limit(1).out("knows")
.limit(1).in("knows")
.limit(1).out("knows")
@@ -259,22 +245,20 @@ public class TinkerGraphPlayTest {
.limit(1).out("knows")
.limit(1).in("knows")
.limit(1).out("knows")
- .limit(1).out("knows")
- .path().by("id");
- assertEquals(toListAndPrint("tripleNested", tripleNested), toListAndPrint("tripleNestedUnfolded", tripleNestedUnfolded));
+ .limit(1).out("knows");
+ assertTrue(CollectionUtils.isEqualCollection(toListAndPrint("tripleNested", tripleNested), toListAndPrint("tripleNestedUnfolded", tripleNestedUnfolded)));
}
@Test
public void testTripleNestedRepeatLimitIncreasedLimit() {
- GraphTraversal<Vertex, Path> tripleNested = g.V().has("id", "l1-0")
+ GraphTraversal<Vertex, Vertex> tripleNested = g.V().has("id", "l1-0")
.repeat(__.limit(2).out("knows")
.repeat(__.limit(3).in("knows")
.repeat(__.limit(4).out("knows"))
.times(2))
.times(2))
- .times(2)
- .path().by("id");
- GraphTraversal<Vertex, Path> tripleNestedUnfolded = g.V().has("id", "l1-0")
+ .times(2);
+ GraphTraversal<Vertex, Vertex> tripleNestedUnfolded = g.V().has("id", "l1-0")
.limit(2).out("knows")
.limit(3).in("knows")
.limit(4).out("knows")
@@ -288,9 +272,8 @@ public class TinkerGraphPlayTest {
.limit(4).out("knows")
.limit(3).in("knows")
.limit(4).out("knows")
- .limit(4).out("knows")
- .path().by("id");
- assertEquals(toListAndPrint("tripleNested", tripleNested), toListAndPrint("tripleNestedUnfolded", tripleNestedUnfolded));
+ .limit(4).out("knows");
+ assertTrue(CollectionUtils.isEqualCollection(toListAndPrint("tripleNested", tripleNested), toListAndPrint("tripleNestedUnfolded", tripleNestedUnfolded)));
}
@Test
@@ -303,7 +286,7 @@ public class TinkerGraphPlayTest {
.limit(1).out("knows").aggregate("x")
.limit(1).out("knows").aggregate("x")
.cap("x");
- assertEquals(toListAndPrint("aggregate", aggregate), toListAndPrint("aggregateUnfolded", aggregateUnfolded));
+ assertTrue(CollectionUtils.isEqualCollection(toListAndPrint("aggregate", aggregate), toListAndPrint("aggregateUnfolded", aggregateUnfolded)));
}
@Test
@@ -316,33 +299,29 @@ public class TinkerGraphPlayTest {
.limit(3).out("knows").aggregate("x")
.limit(3).out("knows").aggregate("x")
.cap("x");
- assertEquals(toListAndPrint("aggregate", aggregate), toListAndPrint("aggregateUnfolded", aggregateUnfolded));
+ assertTrue(CollectionUtils.isEqualCollection(toListAndPrint("aggregate", aggregate), toListAndPrint("aggregateUnfolded", aggregateUnfolded)));
}
@Test
public void testUnionRepeatLimit() {
- GraphTraversal<Vertex, Path> union = g.V().has("id", "l1-0")
+ GraphTraversal<Vertex, Vertex> union = g.V().has("id", "l1-0")
.union(out().limit(1), out().out().limit(1))
- .repeat(__.limit(1)).times(1)
- .path().by("id");
- GraphTraversal<Vertex, Path> unionUnfolded = g.V().has("id", "l1-0")
+ .repeat(__.limit(1)).times(1);
+ GraphTraversal<Vertex, Vertex> unionUnfolded = g.V().has("id", "l1-0")
.union(out().limit(1), out().out().limit(1))
- .limit(1)
- .path().by("id");
- assertEquals(toListAndPrint("union", union), toListAndPrint("unionUnfolded", unionUnfolded));
+ .limit(1);
+ assertTrue(CollectionUtils.isEqualCollection(toListAndPrint("union", union), toListAndPrint("unionUnfolded", unionUnfolded)));
}
@Test
public void testUnionRepeatLimitIncreasedLimit() {
- GraphTraversal<Vertex, Path> union = g.V().has("id", "l1-0")
+ GraphTraversal<Vertex, Vertex> union = g.V().has("id", "l1-0")
.union(out().limit(1), out().out().limit(1))
- .repeat(__.limit(3)).times(1)
- .path().by("id");
- GraphTraversal<Vertex, Path> unionUnfolded = g.V().has("id", "l1-0")
+ .repeat(__.limit(3)).times(1);
+ GraphTraversal<Vertex, Vertex> unionUnfolded = g.V().has("id", "l1-0")
.union(out().limit(1), out().out().limit(1))
- .limit(3)
- .path().by("id");
- assertEquals(toListAndPrint("union", union), toListAndPrint("unionUnfolded", unionUnfolded));
+ .limit(3);
+ assertTrue(CollectionUtils.isEqualCollection(toListAndPrint("union", union), toListAndPrint("unionUnfolded", unionUnfolded)));
}
private List toListAndPrint(String header, GraphTraversal t) {