tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dkupp...@apache.org
Subject [tinkerpop] 01/01: TINKERPOP-2100 coalesce() creating unexpected results when used with order()
Date Mon, 26 Nov 2018 20:48:01 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 6780d05d7eefd3f5f8ec4969366bf110f3be1e14
Author: Daniel Kuppitz <daniel_kuppitz@hotmail.com>
AuthorDate: Mon Nov 26 13:45:50 2018 -0700

    TINKERPOP-2100 coalesce() creating unexpected results when used with order()
---
 CHANGELOG.asciidoc                                      |  1 +
 .../process/traversal/step/map/CoalesceStep.java        |  6 +++++-
 gremlin-test/features/map/Coalesce.feature              | 14 ++++++++++++++
 .../process/traversal/step/map/CoalesceTest.java        | 17 +++++++++++++++++
 4 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 1a0bee5..4972b13 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -25,6 +25,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 
 This release also includes changes from <<release-3-2-11, 3.2.11>>.
 
+* Fixed a bug in `CoalesceStep` which squared the bulk if the step followed a `Barrier` step.
 * Added `:bytecode` command to help developers debugging `Bytecode`-based traversals.
 * Fixed `PersistedOutputRDD` to eager persist RDD by adding `count()` action calls.
 * Deserialized `g:Set` to a Python `Set` in GraphSON in `gremlin-python`.
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/CoalesceStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/CoalesceStep.java
index b80b115..51c315a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/CoalesceStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/CoalesceStep.java
@@ -37,6 +37,8 @@ import java.util.Set;
  */
 public final class CoalesceStep<S, E> extends FlatMapStep<S, E> implements TraversalParent
{
 
+    private Traverser.Admin<S> head = null;
+    private Iterator<E> iterator = EmptyIterator.instance();
     private List<Traversal.Admin<S, E>> coalesceTraversals;
 
     @SafeVarargs
@@ -50,9 +52,11 @@ public final class CoalesceStep<S, E> extends FlatMapStep<S, E>
implements Trave
 
     @Override
     protected Iterator<E> flatMap(final Traverser.Admin<S> traverser) {
+        final Traverser.Admin<S> innerTraverser = traverser.clone().asAdmin();
+        innerTraverser.setBulk(1L);
         for (final Traversal.Admin<S, E> coalesceTraversal : this.coalesceTraversals)
{
             coalesceTraversal.reset();
-            coalesceTraversal.addStart(traverser.split());
+            coalesceTraversal.addStart(innerTraverser.split());
             if (coalesceTraversal.hasNext())
                 return coalesceTraversal;
         }
diff --git a/gremlin-test/features/map/Coalesce.feature b/gremlin-test/features/map/Coalesce.feature
index 8bdac15..3870ee2 100644
--- a/gremlin-test/features/map/Coalesce.feature
+++ b/gremlin-test/features/map/Coalesce.feature
@@ -76,3 +76,17 @@ Feature: Step - coalesce()
       | p[josh,created,ripple] |
       | p[josh,created,lop] |
       | p[peter,created,lop] |
+
+  Scenario: g_V_outXcreatedX_order_byXnameX_coalesceXname_constantXxXX
+    Given the modern graph
+    And the traversal of
+      """
+      g.V().out("created").order().by("name").coalesce(__.values("name"), __.constant("x"))
+      """
+    When iterated to list
+    Then the result should be ordered
+      | result |
+      | lop |
+      | lop |
+      | lop |
+      | ripple |
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/CoalesceTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/CoalesceTest.java
index 9305659..75fd443 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/CoalesceTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/CoalesceTest.java
@@ -35,8 +35,10 @@ import java.util.HashMap;
 import java.util.Map;
 
 import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.constant;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.out;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.outE;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.values;
 import static org.junit.Assert.*;
 
 /**
@@ -55,6 +57,8 @@ public abstract class CoalesceTest extends AbstractGremlinProcessTest {
 
     public abstract Traversal<Vertex, Path> get_g_V_coalesceXoutEXknowsX_outEXcreatedXX_otherV_path_byXnameX_byXlabelX();
 
+    public abstract Traversal<Vertex, String> get_g_V_outXcreatedX_order_byXnameX_coalesceXname_constantXxXX();
+
     @Test
     @LoadGraphWith(MODERN)
     public void g_V_coalesceXoutXfooX_outXbarXX() {
@@ -128,6 +132,14 @@ public abstract class CoalesceTest extends AbstractGremlinProcessTest
{
         assertFalse(traversal.hasNext());
     }
 
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_V_outXcreatedX_order_byXnameX_coalesceXname_constantXxXX() {
+        final Traversal<Vertex, String> traversal = get_g_V_outXcreatedX_order_byXnameX_coalesceXname_constantXxXX();
+        printTraversalForm(traversal);
+        checkResults(Arrays.asList("lop", "lop", "lop", "ripple"), traversal);
+    }
+
     public static class Traversals extends CoalesceTest {
         @Override
         public Traversal<Vertex, Vertex> get_g_V_coalesceXoutXfooX_outXbarXX() {
@@ -153,5 +165,10 @@ public abstract class CoalesceTest extends AbstractGremlinProcessTest
{
         public Traversal<Vertex, Path> get_g_V_coalesceXoutEXknowsX_outEXcreatedXX_otherV_path_byXnameX_byXlabelX()
{
             return g.V().coalesce(outE("knows"), outE("created")).otherV().path().by("name").by(T.label);
         }
+
+        @Override
+        public Traversal<Vertex, String> get_g_V_outXcreatedX_order_byXnameX_coalesceXname_constantXxXX()
{
+            return g.V().out("created").order().by("name").coalesce(values("name"), constant("x"));
+        }
     }
 }


Mime
View raw message