tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dkupp...@apache.org
Subject tinkerpop git commit: TINKERPOP-1958 Fixed a bug in TinkerGraphCountStrategy
Date Wed, 09 May 2018 14:57:53 GMT
Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1958 [created] b30373217


TINKERPOP-1958 Fixed a bug in TinkerGraphCountStrategy

The strategy did not consider, that certain map steps may not emit an element.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/b3037321
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/b3037321
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/b3037321

Branch: refs/heads/TINKERPOP-1958
Commit: b3037321730a9a829e553f887764a769e58f12ee
Parents: 2f8f74a
Author: Daniel Kuppitz <daniel_kuppitz@hotmail.com>
Authored: Wed May 9 07:53:24 2018 -0700
Committer: Daniel Kuppitz <daniel_kuppitz@hotmail.com>
Committed: Wed May 9 07:57:26 2018 -0700

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 .../traversal/step/map/GroovySelectTest.groovy  |  5 ++++
 gremlin-test/features/map/Select.feature        | 22 ++++++++++++++++-
 .../process/traversal/step/map/SelectTest.java  | 15 ++++++++++++
 .../optimization/TinkerGraphCountStrategy.java  |  2 +-
 .../TinkerGraphCountStrategyTest.java           | 25 ++++++++++++--------
 6 files changed, 58 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b3037321/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 18f36ed..b583446 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -23,6 +23,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 [[release-3-2-9]]
 === TinkerPop 3.2.9 (Release Date: May 8, 2018)
 
+* Fixed a bug in `TinkerGraphCountStrategy`, which didn't consider that certain map steps
may not emit an element.
 * Fixed bug where path history was not being preserved for keys in mutations.
 * Bumped to httpclient 4.5.5.
 * Bumped to Groovy 2.4.15 - fixes bug with `Lambda` construction.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b3037321/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovySelectTest.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovySelectTest.groovy
b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovySelectTest.groovy
index 89fc691..104322d 100644
--- a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovySelectTest.groovy
+++ b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovySelectTest.groovy
@@ -104,6 +104,11 @@ public abstract class GroovySelectTest {
             new ScriptTraversal<>(g, "gremlin-groovy", "g.V.choose(__.outE().count().is(0L),
__.as('a'), __.as('b')).choose(select('a'),select('a'),select('b'))")
         }
 
+        @Override
+        public Traversal<Vertex, Long> get_g_V_selectXaX_count() {
+            new ScriptTraversal<>(g, "gremlin-groovy", "g.V.select('a').count")
+        }
+
         // below are original back()-tests
 
         @Override

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b3037321/gremlin-test/features/map/Select.feature
----------------------------------------------------------------------
diff --git a/gremlin-test/features/map/Select.feature b/gremlin-test/features/map/Select.feature
index 35d9322..1e45a0e 100644
--- a/gremlin-test/features/map/Select.feature
+++ b/gremlin-test/features/map/Select.feature
@@ -514,4 +514,24 @@ Feature: Step - select()
     Then the result should be unordered
       | result |
       | d[2].l |
-      | d[2].l |
\ No newline at end of file
+      | d[2].l |
+
+  Scenario: g_V_selectXaX
+    Given the modern graph
+    And the traversal of
+      """
+      g.V().select("a")
+      """
+    When iterated to list
+    Then the result should be empty
+
+  Scenario: g_V_selectXaX_count
+    Given the modern graph
+    And the traversal of
+      """
+      g.V().select("a").count()
+      """
+    When iterated to list
+    Then the result should be unordered
+      | result |
+      | d[0].l |

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b3037321/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SelectTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SelectTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SelectTest.java
index c0486d0..3d778e4 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SelectTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SelectTest.java
@@ -83,6 +83,8 @@ public abstract class SelectTest extends AbstractGremlinProcessTest {
 
     public abstract Traversal<Vertex, Vertex> get_g_V_chooseXoutE_count_isX0X__asXaX__asXbXX_chooseXselectXaX__selectXaX__selectXbXX();
 
+    public abstract Traversal<Vertex, Long> get_g_V_selectXaX_count();
+
     // below are original back()-tests
 
     public abstract Traversal<Vertex, Vertex> get_g_VX1X_asXhereX_out_selectXhereX(final
Object v1Id);
@@ -344,6 +346,14 @@ public abstract class SelectTest extends AbstractGremlinProcessTest {
         assertEquals(3, xCounter);
     }
 
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_V_selectXaX_count() {
+        final Traversal<Vertex, Long> traversal = get_g_V_selectXaX_count();
+        printTraversalForm(traversal);
+        assertEquals(0L, traversal.next().longValue());
+    }
+
     // below are original back()-tests
 
     @Test
@@ -725,6 +735,11 @@ public abstract class SelectTest extends AbstractGremlinProcessTest {
             return g.V().choose(__.outE().count().is(0L), __.as("a"), __.as("b")).choose(__.select("a"),
__.select("a"), __.select("b"));
         }
 
+        @Override
+        public Traversal<Vertex, Long> get_g_V_selectXaX_count() {
+            return g.V().select("a").count();
+        }
+
         // below are original back()-tests
 
         @Override

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b3037321/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategy.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategy.java
b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategy.java
index 50e5c18..55e6b55 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategy.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategy.java
@@ -71,7 +71,7 @@ public final class TinkerGraphCountStrategy extends AbstractTraversalStrategy<Tr
             return;
         for (int i = 1; i < steps.size() - 1; i++) {
             final Step current = steps.get(i);
-            if (!(current instanceof MapStep ||
+            if (!(//current instanceof MapStep ||  // MapSteps will not necessarily emit
an element as demonstrated in https://issues.apache.org/jira/browse/TINKERPOP-1958
                     current instanceof IdentityStep ||
                     current instanceof NoOpBarrierStep ||
                     current instanceof CollectingBarrierStep) ||

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b3037321/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategyTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategyTest.java
b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategyTest.java
index 0db378b..ec9bd93 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategyTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategyTest.java
@@ -64,6 +64,11 @@ public class TinkerGraphCountStrategyTest {
         for (final TraversalStrategy strategy : this.otherStrategies) {
             strategies.addStrategies(strategy);
         }
+        if (this.optimized == null) {
+            this.optimized = this.original.asAdmin().clone();
+            this.optimized.asAdmin().setStrategies(strategies);
+            this.optimized.asAdmin().applyStrategies();
+        }
         this.original.asAdmin().setStrategies(strategies);
         this.original.asAdmin().applyStrategies();
         assertEquals(this.optimized, this.original);
@@ -81,17 +86,17 @@ public class TinkerGraphCountStrategyTest {
                 {__.V().count(), countStep(Vertex.class), TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
                 {__.V().as("a").count(), countStep(Vertex.class), TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
                 {__.V().count().as("a"), countStep(Vertex.class), TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
-                {__.V().map(out()).count().as("a"), countStep(Vertex.class), TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
-                {__.V().map(out()).identity().count().as("a"), countStep(Vertex.class), TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
-                {__.V().map(out().groupCount()).identity().count().as("a"), countStep(Vertex.class),
TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
-                {__.V().label().map(s -> s.get().length()).count(), countStep(Vertex.class),
TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
-                {__.V().as("a").map(select("a")).count(), countStep(Vertex.class),TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
+                {__.V().map(out()).count().as("a"), null, TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
+                {__.V().map(out()).identity().count().as("a"), null, TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
+                {__.V().map(out().groupCount()).identity().count().as("a"), null, TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
+                {__.V().label().map(s -> s.get().length()).count(), null, TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
+                {__.V().as("a").map(select("a")).count(), null, TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
                 //
-                {__.V(), __.V(), Collections.emptyList()},
-                {__.V().out().count(), __.V().out().count(), Collections.emptyList()},
-                {__.V(1).count(), __.V(1).count(), Collections.emptyList()},
-                {__.count(), __.count(), Collections.emptyList()},
-                {__.V().map(out().groupCount("m")).identity().count().as("a"), __.V().map(out().groupCount("m")).identity().count().as("a"),
Collections.emptyList()},
+                {__.V(), null, Collections.emptyList()},
+                {__.V().out().count(), null, Collections.emptyList()},
+                {__.V(1).count(), null, Collections.emptyList()},
+                {__.count(), null, Collections.emptyList()},
+                {__.V().map(out().groupCount("m")).identity().count().as("a"), null, Collections.emptyList()},
         });
     }
 }


Mime
View raw message