tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dkupp...@apache.org
Subject [1/4] tinkerpop git commit: Fixed the behavior of `min()`, `max()`, and `mean()`. If no input is given, these steps will now throw a `FastNoElementException`.
Date Sat, 17 Feb 2018 05:22:30 GMT
Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1777-master [created] 7cae75af4


Fixed the behavior of `min()`, `max()`, and `mean()`.
If no input is given, these steps will now throw a `FastNoElementException`.


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

Branch: refs/heads/TINKERPOP-1777-master
Commit: f69c715fe837d21bcc8f34efe2aaa72021b53088
Parents: 041bb3f
Author: Daniel Kuppitz <daniel_kuppitz@hotmail.com>
Authored: Wed Feb 7 08:18:17 2018 -0700
Committer: Daniel Kuppitz <daniel_kuppitz@hotmail.com>
Committed: Wed Feb 14 18:32:44 2018 -0700

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 .../traversal/step/map/ComputerResultStep.java  |  4 +-
 .../process/traversal/step/filter/AndStep.java  |  3 +-
 .../traversal/step/map/MaxGlobalStep.java       |  8 +++-
 .../traversal/step/map/MaxLocalStep.java        |  9 ++--
 .../traversal/step/map/MeanGlobalStep.java      |  6 +++
 .../traversal/step/map/MeanLocalStep.java       |  4 +-
 .../traversal/step/map/MinGlobalStep.java       |  6 +++
 .../traversal/step/map/MinLocalStep.java        |  9 ++--
 .../process/traversal/step/map/MaxTest.java     | 48 +++++++++++++++++++-
 .../process/traversal/step/map/MeanTest.java    | 43 ++++++++++++++++--
 .../process/traversal/step/map/MinTest.java     | 46 +++++++++++++++++++
 .../SparkStarBarrierInterceptor.java            | 32 +++++++------
 .../structure/TinkerGraphPlayTest.java          |  7 +--
 14 files changed, 185 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f69c715f/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index b735361..4c1efb0 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -272,6 +272,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 [[release-3-2-8]]
 === TinkerPop 3.2.8 (Release Date: NOT OFFICIALLY RELEASED YET)
 
+* Fixed a bug in `ReducingBarrierStep`, that returned the provided seed value despite no
elements being available.
 * Modified `GremlinDslProcessor` so that it generated the `getAnonymousTraversalClass()`
method to return the DSL version of `__`.
 * Added the "Kitchen Sink" test data set.
 * Fixed a bug in `NumberHelper` that led to wrong min/max results if numbers exceeded the
Integer limits.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f69c715f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/ComputerResultStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/ComputerResultStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/ComputerResultStep.java
index b5fd8e8..95e572d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/ComputerResultStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/ComputerResultStep.java
@@ -66,7 +66,9 @@ public final class ComputerResultStep<S> extends AbstractStep<ComputerResult,
S>
                 return this.currentIterator.next();
             else {
                 final ComputerResult result = this.starts.next().get();
-                this.currentIterator = attach(result.memory().<TraverserSet<S>>get(TraversalVertexProgram.HALTED_TRAVERSERS).iterator(),
result.graph());
+                this.currentIterator = attach(result.memory().exists(TraversalVertexProgram.HALTED_TRAVERSERS)
+                        ? result.memory().<TraverserSet<S>>get(TraversalVertexProgram.HALTED_TRAVERSERS).iterator()
+                        : EmptyIterator.instance(), result.graph());
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f69c715f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/AndStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/AndStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/AndStep.java
index 5d9d124..d66dde4 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/AndStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/AndStep.java
@@ -36,7 +36,6 @@ public final class AndStep<S> extends ConnectiveStep<S> {
         for (final Traversal.Admin<S, ?> traversal : this.traversals) {
             if (!TraversalUtil.test(traverser, traversal))
                 return false;
-        }
         return true;
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f69c715f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MaxGlobalStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MaxGlobalStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MaxGlobalStep.java
index 954dbfe..8cb798c 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MaxGlobalStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MaxGlobalStep.java
@@ -41,7 +41,13 @@ public final class MaxGlobalStep<S extends Number> extends ReducingBarrierStep<S
     }
 
     @Override
-    public S projectTraverser(Traverser.Admin<S> traverser) {
+    public void processAllStarts() {
+        if (this.starts.hasNext())
+            super.processAllStarts();
+    }
+
+    @Override
+    public S projectTraverser(final Traverser.Admin<S> traverser) {
         return traverser.get();
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f69c715f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MaxLocalStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MaxLocalStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MaxLocalStep.java
index 2baca28..909a4c7 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MaxLocalStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MaxLocalStep.java
@@ -21,6 +21,7 @@ package org.apache.tinkerpop.gremlin.process.traversal.step.map;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
+import org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException;
 
 import java.util.Collections;
 import java.util.Iterator;
@@ -40,17 +41,15 @@ public final class MaxLocalStep<E extends Number, S extends Iterable<E>>
extends
 
     @Override
     protected E map(final Traverser.Admin<S> traverser) {
-        Number result;
         final Iterator<E> iterator = traverser.get().iterator();
         if (iterator.hasNext()) {
-            result = iterator.next();
+            Number result = iterator.next();
             while (iterator.hasNext()) {
                 result = max(iterator.next(), result);
             }
-        } else {
-            result = Double.NaN;
+            return (E) result;
         }
-        return (E) result;
+        throw FastNoSuchElementException.instance();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f69c715f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanGlobalStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanGlobalStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanGlobalStep.java
index 2f1c1dc..5e90336 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanGlobalStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanGlobalStep.java
@@ -49,6 +49,12 @@ public final class MeanGlobalStep<S extends Number, E extends Number>
extends Re
     }
 
     @Override
+    public void processAllStarts() {
+        if (this.starts.hasNext())
+            super.processAllStarts();
+    }
+
+    @Override
     public E projectTraverser(final Traverser.Admin<S> traverser) {
         return (E) new MeanNumber(traverser.get(), traverser.bulk());
     }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f69c715f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanLocalStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanLocalStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanLocalStep.java
index 99005c9..91447fd 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanLocalStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanLocalStep.java
@@ -22,6 +22,7 @@ import org.apache.tinkerpop.gremlin.util.NumberHelper;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
+import org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException;
 
 import java.util.Collections;
 import java.util.Iterator;
@@ -48,9 +49,8 @@ public final class MeanLocalStep<E extends Number, S extends Iterable<E>>
extend
                 counter++;
             }
             return NumberHelper.div(result, counter, true);
-        } else {
-            return Double.NaN;
         }
+        throw FastNoSuchElementException.instance();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f69c715f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MinGlobalStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MinGlobalStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MinGlobalStep.java
index 7d0eb56..e476f5c 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MinGlobalStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MinGlobalStep.java
@@ -41,6 +41,12 @@ public final class MinGlobalStep<S extends Number> extends ReducingBarrierStep<S
     }
 
     @Override
+    public void processAllStarts() {
+        if (this.starts.hasNext())
+            super.processAllStarts();
+    }
+
+    @Override
     public S projectTraverser(final Traverser.Admin<S> traverser) {
         return traverser.get();
     }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f69c715f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MinLocalStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MinLocalStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MinLocalStep.java
index e7e001c..64c89e3 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MinLocalStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MinLocalStep.java
@@ -21,6 +21,7 @@ package org.apache.tinkerpop.gremlin.process.traversal.step.map;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
+import org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException;
 
 import java.util.Collections;
 import java.util.Iterator;
@@ -40,17 +41,15 @@ public final class MinLocalStep<E extends Number, S extends Iterable<E>>
extends
 
     @Override
     protected E map(final Traverser.Admin<S> traverser) {
-        Number result;
         final Iterator<E> iterator = traverser.get().iterator();
         if (iterator.hasNext()) {
-            result = iterator.next();
+            Number result = iterator.next();
             while (iterator.hasNext()) {
                 result = min(iterator.next(), result);
             }
-        } else {
-            result = Double.NaN;
+            return (E) result;
         }
-        return (E) result;
+        throw FastNoSuchElementException.instance();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f69c715f/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MaxTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MaxTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MaxTest.java
index fae3f92..f13cdb5 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MaxTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MaxTest.java
@@ -21,6 +21,7 @@ package org.apache.tinkerpop.gremlin.process.traversal.step.map;
 import org.apache.tinkerpop.gremlin.LoadGraphWith;
 import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
 import org.apache.tinkerpop.gremlin.process.GremlinProcessRunner;
+import org.apache.tinkerpop.gremlin.process.traversal.Scope;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.junit.Test;
@@ -41,6 +42,12 @@ public abstract class MaxTest extends AbstractGremlinProcessTest {
 
     public abstract Traversal<Vertex, Integer> get_g_V_age_max();
 
+    public abstract Traversal<Vertex, Integer> get_g_V_age_fold_maxXlocalX();
+
+    public abstract Traversal<Vertex, Number> get_g_V_foo_max();
+
+    public abstract Traversal<Vertex, Number> get_g_V_foo_fold_maxXlocalX();
+
     public abstract Traversal<Vertex, Integer> get_g_V_repeatXbothX_timesX5X_age_max();
 
     public abstract Traversal<Vertex, Map<String, Number>> get_g_V_hasLabelXsoftwareX_group_byXnameX_byXbothE_weight_maxX();
@@ -55,6 +62,30 @@ public abstract class MaxTest extends AbstractGremlinProcessTest {
 
     @Test
     @LoadGraphWith(MODERN)
+    public void g_V_age_fold_maxXlocalX() {
+        final Traversal<Vertex, Integer> traversal = get_g_V_age_fold_maxXlocalX();
+        printTraversalForm(traversal);
+        checkResults(Arrays.asList(35), traversal);
+    }
+
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_V_foo_max() {
+        final Traversal<Vertex, Number> traversal = get_g_V_foo_max();
+        printTraversalForm(traversal);
+        assertFalse(traversal.hasNext());
+    }
+
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_V_foo_fold_maxXlocalX() {
+        final Traversal<Vertex, Number> traversal = get_g_V_foo_fold_maxXlocalX();
+        printTraversalForm(traversal);
+        assertFalse(traversal.hasNext());
+    }
+
+    @Test
+    @LoadGraphWith(MODERN)
     public void g_V_repeatXbothX_timesX5X_age_max() {
         final Traversal<Vertex, Integer> traversal = get_g_V_repeatXbothX_timesX5X_age_max();
         printTraversalForm(traversal);
@@ -82,6 +113,21 @@ public abstract class MaxTest extends AbstractGremlinProcessTest {
         }
 
         @Override
+        public Traversal<Vertex, Integer> get_g_V_age_fold_maxXlocalX() {
+            return g.V().values("age").fold().max(Scope.local);
+        }
+
+        @Override
+        public Traversal<Vertex, Number> get_g_V_foo_max() {
+            return g.V().values("foo").max();
+        }
+
+        @Override
+        public Traversal<Vertex, Number> get_g_V_foo_fold_maxXlocalX() {
+            return g.V().values("foo").fold().max(Scope.local);
+        }
+
+        @Override
         public Traversal<Vertex, Integer> get_g_V_repeatXbothX_timesX5X_age_max() {
             return g.V().repeat(both()).times(5).values("age").max();
         }
@@ -91,4 +137,4 @@ public abstract class MaxTest extends AbstractGremlinProcessTest {
             return g.V().hasLabel("software").<String, Number>group().by("name").by(bothE().values("weight").max());
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f69c715f/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanTest.java
index ab47605..34bef6d 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanTest.java
@@ -21,11 +21,13 @@ package org.apache.tinkerpop.gremlin.process.traversal.step.map;
 import org.apache.tinkerpop.gremlin.LoadGraphWith;
 import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
 import org.apache.tinkerpop.gremlin.process.GremlinProcessRunner;
+import org.apache.tinkerpop.gremlin.process.traversal.Scope;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import java.util.Arrays;
 import java.util.Map;
 
 import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
@@ -40,16 +42,32 @@ public abstract class MeanTest extends AbstractGremlinProcessTest {
 
     public abstract Traversal<Vertex, Double> get_g_V_age_mean();
 
+    public abstract Traversal<Vertex, Double> get_g_V_age_fold_meanXlocalX();
+
+    public abstract Traversal<Vertex, Number> get_g_V_foo_mean();
+
+    public abstract Traversal<Vertex, Number> get_g_V_foo_fold_meanXlocalX();
+
     public abstract Traversal<Vertex, Map<String, Number>> get_g_V_hasLabelXsoftwareX_group_byXnameX_byXbothE_weight_meanX();
 
     @Test
     @LoadGraphWith(MODERN)
     public void g_V_age_mean() {
-        final Traversal<Vertex, Double> traversal = get_g_V_age_mean();
-        printTraversalForm(traversal);
-        final Double mean = traversal.next();
-        assertEquals(30.75, mean, 0.05);
-        assertFalse(traversal.hasNext());
+        for (final Traversal<Vertex, Double> traversal : Arrays.asList(get_g_V_age_mean(),
get_g_V_age_fold_meanXlocalX())) {
+            printTraversalForm(traversal);
+            final Double mean = traversal.next();
+            assertEquals(30.75, mean, 0.05);
+            assertFalse(traversal.hasNext());
+        }
+    }
+
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_V_foo_mean() {
+        for (final Traversal<Vertex, Number> traversal : Arrays.asList(get_g_V_foo_mean(),
get_g_V_foo_fold_meanXlocalX())) {
+            printTraversalForm(traversal);
+            assertFalse(traversal.hasNext());
+        }
     }
 
     @Test
@@ -73,6 +91,21 @@ public abstract class MeanTest extends AbstractGremlinProcessTest {
         }
 
         @Override
+        public Traversal<Vertex, Double> get_g_V_age_fold_meanXlocalX() {
+            return g.V().values("age").fold().mean(Scope.local);
+        }
+
+        @Override
+        public Traversal<Vertex, Number> get_g_V_foo_mean() {
+            return g.V().values("foo").mean();
+        }
+
+        @Override
+        public Traversal<Vertex, Number> get_g_V_foo_fold_meanXlocalX() {
+            return g.V().values("foo").fold().mean(Scope.local);
+        }
+
+        @Override
         public Traversal<Vertex, Map<String, Number>> get_g_V_hasLabelXsoftwareX_group_byXnameX_byXbothE_weight_meanX()
{
             return g.V().hasLabel("software").<String, Number>group().by("name").by(bothE().values("weight").mean());
         }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f69c715f/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MinTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MinTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MinTest.java
index 947137f..10f6bc8 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MinTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MinTest.java
@@ -21,6 +21,7 @@ package org.apache.tinkerpop.gremlin.process.traversal.step.map;
 import org.apache.tinkerpop.gremlin.LoadGraphWith;
 import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
 import org.apache.tinkerpop.gremlin.process.GremlinProcessRunner;
+import org.apache.tinkerpop.gremlin.process.traversal.Scope;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.junit.Test;
@@ -43,6 +44,12 @@ public abstract class MinTest extends AbstractGremlinProcessTest {
 
     public abstract Traversal<Vertex, Integer> get_g_V_age_min();
 
+    public abstract Traversal<Vertex, Integer> get_g_V_age_fold_minXlocalX();
+
+    public abstract Traversal<Vertex, Number> get_g_V_foo_min();
+
+    public abstract Traversal<Vertex, Number> get_g_V_foo_fold_minXlocalX();
+
     public abstract Traversal<Vertex, Integer> get_g_V_repeatXbothX_timesX5X_age_min();
 
     public abstract Traversal<Vertex, Map<String, Number>> get_g_V_hasLabelXsoftwareX_group_byXnameX_byXbothE_weight_minX();
@@ -59,6 +66,30 @@ public abstract class MinTest extends AbstractGremlinProcessTest {
 
     @Test
     @LoadGraphWith(MODERN)
+    public void g_V_age_fold_minXlocalX() {
+        final Traversal<Vertex, Integer> traversal = get_g_V_age_fold_minXlocalX();
+        printTraversalForm(traversal);
+        checkResults(Arrays.asList(27), traversal);
+    }
+
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_V_foo_min() {
+        final Traversal<Vertex, Number> traversal = get_g_V_foo_min();
+        printTraversalForm(traversal);
+        assertFalse(traversal.hasNext());
+    }
+
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_V_foo_fold_minXlocalX() {
+        final Traversal<Vertex, Number> traversal = get_g_V_foo_fold_minXlocalX();
+        printTraversalForm(traversal);
+        assertFalse(traversal.hasNext());
+    }
+
+    @Test
+    @LoadGraphWith(MODERN)
     public void g_V_repeatXbothX_timesX5X_age_min() {
         final Traversal<Vertex, Integer> traversal = get_g_V_repeatXbothX_timesX5X_age_min();
         printTraversalForm(traversal);
@@ -96,6 +127,21 @@ public abstract class MinTest extends AbstractGremlinProcessTest {
         }
 
         @Override
+        public Traversal<Vertex, Integer> get_g_V_age_fold_minXlocalX() {
+            return g.V().values("age").fold().min(Scope.local);
+        }
+
+        @Override
+        public Traversal<Vertex, Number> get_g_V_foo_min() {
+            return g.V().values("foo").min();
+        }
+
+        @Override
+        public Traversal<Vertex, Number> get_g_V_foo_fold_minXlocalX() {
+            return g.V().values("foo").fold().min(Scope.local);
+        }
+
+        @Override
         public Traversal<Vertex, Integer> get_g_V_repeatXbothX_timesX5X_age_min() {
             return g.V().repeat(both()).times(5).values("age").min();
         }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f69c715f/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/process/computer/traversal/strategy/optimization/interceptor/SparkStarBarrierInterceptor.java
----------------------------------------------------------------------
diff --git a/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/process/computer/traversal/strategy/optimization/interceptor/SparkStarBarrierInterceptor.java
b/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/process/computer/traversal/strategy/optimization/interceptor/SparkStarBarrierInterceptor.java
index 3c74e5a..3c89c1d 100644
--- a/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/process/computer/traversal/strategy/optimization/interceptor/SparkStarBarrierInterceptor.java
+++ b/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/process/computer/traversal/strategy/optimization/interceptor/SparkStarBarrierInterceptor.java
@@ -45,6 +45,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.Subgra
 import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ComputerVerificationStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.util.TraverserSet;
+import org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException;
 import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
 import org.apache.tinkerpop.gremlin.spark.process.computer.SparkMemory;
 import org.apache.tinkerpop.gremlin.spark.process.computer.traversal.strategy.SparkVertexProgramInterceptor;
@@ -52,6 +53,7 @@ import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
 import org.apache.tinkerpop.gremlin.util.NumberHelper;
 import org.apache.tinkerpop.gremlin.util.function.ArrayListSupplier;
+import org.apache.tinkerpop.gremlin.util.function.MeanNumberSupplier;
 import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
 
 import java.util.ArrayList;
@@ -97,24 +99,24 @@ public final class SparkStarBarrierInterceptor implements SparkVertexProgramInte
         final Object result;
         if (endStep instanceof CountGlobalStep)
             result = nextRDD.map(Traverser::bulk).fold(0l, (a, b) -> a + b);
-        else if (endStep instanceof SumGlobalStep)
+        else if (endStep instanceof SumGlobalStep) {
             result = nextRDD
                     .map(traverser -> NumberHelper.mul(traverser.bulk(), (Number) traverser.get()))
                     .fold(0, NumberHelper::add);
-        else if (endStep instanceof MeanGlobalStep)
-            result = nextRDD
+        } else if (endStep instanceof MeanGlobalStep) {
+            result = nextRDD.isEmpty() ? null : nextRDD
                     .map(traverser -> new MeanGlobalStep.MeanNumber((Number) traverser.get(),
traverser.bulk()))
-                    .fold(new MeanGlobalStep.MeanNumber(), MeanGlobalStep.MeanNumber::add)
+                    .fold(MeanNumberSupplier.instance().get(), MeanGlobalStep.MeanNumber::add)
                     .getFinal();
-        else if (endStep instanceof MinGlobalStep)
-            result = nextRDD
+        } else if (endStep instanceof MinGlobalStep) {
+            result = nextRDD.isEmpty() ? null : nextRDD
                     .map(traverser -> (Number) traverser.get())
-                    .fold(Integer.MAX_VALUE, NumberHelper::min);
-        else if (endStep instanceof MaxGlobalStep)
-            result = nextRDD
+                    .fold(Double.NaN, NumberHelper::min);
+        } else if (endStep instanceof MaxGlobalStep) {
+            result = nextRDD.isEmpty() ? null : nextRDD
                     .map(traverser -> (Number) traverser.get())
-                    .fold(Integer.MIN_VALUE, NumberHelper::max);
-        else if (endStep instanceof FoldStep) {
+                    .fold(Double.NaN, NumberHelper::max);
+        } else if (endStep instanceof FoldStep) {
             final BinaryOperator biOperator = endStep.getBiOperator();
             result = nextRDD.map(traverser -> {
                 if (endStep.getSeedSupplier() instanceof ArrayListSupplier) {
@@ -148,9 +150,11 @@ public final class SparkStarBarrierInterceptor implements SparkVertexProgramInte
         ///////////////////////////////
 
         // generate the HALTED_TRAVERSERS for the memory
-        final TraverserSet<Long> haltedTraversers = new TraverserSet<>();
-        haltedTraversers.add(traversal.getTraverserGenerator().generate(result, endStep,
1l)); // all reducing barrier steps produce a result of bulk 1
-        memory.set(TraversalVertexProgram.HALTED_TRAVERSERS, haltedTraversers);
+        if (result != null) {
+            final TraverserSet<Long> haltedTraversers = new TraverserSet<>();
+            haltedTraversers.add(traversal.getTraverserGenerator().generate(result, endStep,
1l)); // all reducing barrier steps produce a result of bulk 1
+            memory.set(TraversalVertexProgram.HALTED_TRAVERSERS, haltedTraversers);
+        }
         memory.incrIteration(); // any local star graph reduction takes a single iteration
         return inputRDD;
     }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f69c715f/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
----------------------------------------------------------------------
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 a13a4ad..eacc3db 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
@@ -132,11 +132,8 @@ public class TinkerGraphPlayTest {
     public void testPlayDK() throws Exception {
 
         Graph graph = TinkerGraph.open();
-        GraphTraversalSource g = graph.traversal();
-        graph.io(GraphMLIo.build()).readGraph("/projects/apache/tinkerpop/data/grateful-dead.xml");
-        System.out.println(g.V().filter(outE("sungBy").count().is(0)).explain());
-        System.out.println(g.V().filter(outE("sungBy").count().is(lt(1))).explain());
-        System.out.println(g.V().filter(outE("sungBy").count().is(1)).explain());
+        GraphTraversalSource g = graph.traversal().withComputer();
+        g.V().values("test").max().forEachRemaining(System.out::println);
     }
 
     @Test


Mime
View raw message