You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2019/07/01 23:09:00 UTC

[tinkerpop] 01/01: TINKERPOP-1619 Treat optional() traversal as local child

This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a commit to branch TINKERPOP-1619
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit 5d9b20f966f5493a93d6d1d93253a147164222a9
Author: Stephen Mallette <sp...@genoprime.com>
AuthorDate: Mon Jul 1 14:42:34 2019 -0400

    TINKERPOP-1619 Treat optional() traversal as local child
---
 CHANGELOG.asciidoc                                           |  1 +
 .../gremlin/process/traversal/step/branch/OptionalStep.java  |  1 +
 .../gremlin/tinkergraph/structure/TinkerGraphTest.java       | 12 ++++++++++++
 3 files changed, 14 insertions(+)

diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 0cd6c8a..3a17028 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -29,6 +29,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 * Improved exception and messaging for gt/gte/lt/lte when one of the object isn't a `Comparable`.
 * Added test infrastructure to check for storage iterator leak.
 * Fixed multiple iterator leaks in query processor.
+* Fixed `optional()` so that the child traversal is treated as local.
 * Improved error messaging for invalid inputs to the TinkerGraph `IdManager` instances.
 * Forced replacement of connections in Java driver for certain exception types that seem to ultimately kill the connection.
 * Changed the `reverse()` of `desc` and `asc` on `Order` to not use the deprecated `decr` and `incr`.
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/OptionalStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/OptionalStep.java
index 1e7fb26..ce7bab9 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/OptionalStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/OptionalStep.java
@@ -49,6 +49,7 @@ public final class OptionalStep<S> extends AbstractStep<S, S> implements Travers
             return this.optionalTraversal.nextTraverser();
         else {
             final Traverser.Admin<S> traverser = this.starts.next();
+            this.optionalTraversal.reset();
             this.optionalTraversal.addStart(traverser.split());
             if (this.optionalTraversal.hasNext())
                 return this.optionalTraversal.nextTraverser();
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
index a4408af..9f7fb32 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
@@ -22,6 +22,7 @@ import org.apache.commons.configuration.BaseConfiguration;
 import org.apache.commons.configuration.Configuration;
 import org.apache.tinkerpop.gremlin.GraphHelper;
 import org.apache.tinkerpop.gremlin.TestHelper;
+import org.apache.tinkerpop.gremlin.process.computer.Computer;
 import org.apache.tinkerpop.gremlin.process.traversal.P;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
@@ -668,6 +669,17 @@ public class TinkerGraphTest {
         assertThat(g.V("id").hasNext(), is(true));
     }
 
+    @Test
+    public void shouldOptionalUsingWithComputer() {
+        // didn't add this as a general test as it basically was only failing under a specific condition for
+        // TinkerGraphComputer - see more here: https://issues.apache.org/jira/browse/TINKERPOP-1619
+        GraphTraversalSource g = TinkerFactory.createModern().traversal();
+
+        final List<Edge> expected = g.E(7, 7, 8, 9).order().by(T.id).toList();
+        assertEquals(expected, g.withComputer(Computer.compute().workers(3)).V(1, 2).optional(__.bothE().dedup()).order().by(T.id).toList());
+        assertEquals(expected, g.withComputer(Computer.compute().workers(4)).V(1, 2).optional(__.bothE().dedup()).order().by(T.id).toList());
+    }
+
     /**
      * Coerces a {@code Color} to a {@link TinkerGraph} during serialization.  Demonstrates how custom serializers
      * can be developed that can coerce one value to another during serialization.