Fixed the behavior of `min()`, `max()`, `mean()` and `sum()`.
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/fb05ea79
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/fb05ea79
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/fb05ea79

Branch: refs/heads/TINKERPOP-1777
Commit: fb05ea797ae95611ce03b6b027513a79567b6a25
Parents: cef13dd
Author: Daniel Kuppitz <daniel_kupp...@hotmail.com>
Authored: Tue Feb 27 10:15:07 2018 -0700
Committer: Daniel Kuppitz <daniel_kupp...@hotmail.com>
Committed: Thu Mar 1 09:20:29 2018 -0700

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  2 +
 .../traversal/step/map/ComputerResultStep.java  |  4 +-
 .../process/traversal/step/filter/AndStep.java  |  2 +-
 .../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 ++-
 .../traversal/step/map/SumGlobalStep.java       |  8 ++-
 .../traversal/step/map/SumLocalStep.java        |  9 ++-
 .../process/traversal/step/map/MaxTest.java     | 48 +++++++++++++++-
 .../process/traversal/step/map/MeanTest.java    | 43 ++++++++++++--
 .../process/traversal/step/map/MinTest.java     | 46 +++++++++++++++
 .../process/traversal/step/map/SumTest.java     | 60 ++++++++++++++++++--
 .../SparkStarBarrierInterceptor.java            | 32 ++++++-----
 .../structure/TinkerGraphPlayTest.java          |  7 +--
 17 files changed, 251 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fb05ea79/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 26d53b4..a07128b 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -25,6 +25,8 @@ NEED AND IMAGE
 
 This release also includes changes from <<release-3-3-2, 3.3.2>>.
 
+* Fixed a bug in `ReducingBarrierStep`, that returned the provided seed value 
despite no elements being available.
+
 
 == TinkerPop 3.3.0 (Gremlin Symphony #40 in G Minor)
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fb05ea79/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/fb05ea79/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..5c20cd8 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
@@ -39,4 +39,4 @@ public final class AndStep<S> extends ConnectiveStep<S> {
         }
         return true;
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fb05ea79/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/fb05ea79/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/fb05ea79/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/fb05ea79/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/fb05ea79/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/fb05ea79/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/fb05ea79/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumGlobalStep.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumGlobalStep.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumGlobalStep.java
index 7942d9b..3711cfe 100644
--- 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumGlobalStep.java
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumGlobalStep.java
@@ -48,6 +48,12 @@ public final class SumGlobalStep<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 (S) mul(traverser.get(), traverser.bulk());
     }
@@ -57,4 +63,4 @@ public final class SumGlobalStep<S extends Number> extends 
ReducingBarrierStep<S
     public Set<TraverserRequirement> getRequirements() {
         return REQUIREMENTS;
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fb05ea79/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumLocalStep.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumLocalStep.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumLocalStep.java
index b062a7e..72e6539 100644
--- 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumLocalStep.java
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumLocalStep.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;
@@ -39,17 +40,15 @@ public final class SumLocalStep<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 = NumberHelper.add(result, iterator.next());
             }
-        } else {
-            result = 0;
+            return (E) result;
         }
-        return (E) result;
+        throw FastNoSuchElementException.instance();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fb05ea79/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/fb05ea79/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/fb05ea79/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/fb05ea79/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumTest.java
----------------------------------------------------------------------
diff --git 
a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumTest.java
 
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumTest.java
index 1183863..e1bbd0b 100644
--- 
a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumTest.java
+++ 
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumTest.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;
@@ -39,17 +40,49 @@ import static org.junit.Assert.*;
 @RunWith(GremlinProcessRunner.class)
 public abstract class SumTest extends AbstractGremlinProcessTest {
 
-    public abstract Traversal<Vertex, Double> get_g_V_valuesXageX_sum();
+    public abstract Traversal<Vertex, Integer> get_g_V_valuesXageX_sum();
+
+    public abstract Traversal<Vertex, Integer> get_g_V_age_fold_sumXlocalX();
+
+    public abstract Traversal<Vertex, Number> get_g_V_foo_sum();
+
+    public abstract Traversal<Vertex, Number> get_g_V_foo_fold_sumXlocalX();
 
     public abstract Traversal<Vertex, Map<String, Number>> 
get_g_V_hasLabelXsoftwareX_group_byXnameX_byXbothE_weight_sumX();
 
     @Test
     @LoadGraphWith(MODERN)
     public void g_V_valuesXageX_sum() {
-        final Traversal<Vertex, Double> traversal = get_g_V_valuesXageX_sum();
+        final Traversal<Vertex, Integer> traversal = get_g_V_valuesXageX_sum();
+        printTraversalForm(traversal);
+        final Integer sum = traversal.next();
+        assertEquals(123, sum.intValue());
+        assertFalse(traversal.hasNext());
+    }
+
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_V_age_fold_sumXlocalX() {
+        final Traversal<Vertex, Integer> traversal = 
get_g_V_age_fold_sumXlocalX();
+        printTraversalForm(traversal);
+        final Integer sum = traversal.next();
+        assertEquals(123, sum.intValue());
+        assertFalse(traversal.hasNext());
+    }
+
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_V_foo_sum() {
+        final Traversal<Vertex, Number> traversal = get_g_V_foo_sum();
+        printTraversalForm(traversal);
+        assertFalse(traversal.hasNext());
+    }
+
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_V_foo_fold_sumXlocalX() {
+        final Traversal<Vertex, Number> traversal = 
get_g_V_foo_fold_sumXlocalX();
         printTraversalForm(traversal);
-        final Number sum = traversal.next();
-        assertEquals(123L, sum);
         assertFalse(traversal.hasNext());
     }
 
@@ -69,13 +102,28 @@ public abstract class SumTest extends 
AbstractGremlinProcessTest {
     public static class Traversals extends SumTest {
 
         @Override
-        public Traversal<Vertex, Double> get_g_V_valuesXageX_sum() {
+        public Traversal<Vertex, Integer> get_g_V_valuesXageX_sum() {
             return g.V().values("age").sum();
         }
 
         @Override
+        public Traversal<Vertex, Integer> get_g_V_age_fold_sumXlocalX() {
+            return g.V().values("age").fold().sum(Scope.local);
+        }
+
+        @Override
+        public Traversal<Vertex, Number> get_g_V_foo_sum() {
+            return g.V().values("foo").sum();
+        }
+
+        @Override
+        public Traversal<Vertex, Number> get_g_V_foo_fold_sumXlocalX() {
+            return g.V().values("foo").fold().sum(Scope.local);
+        }
+
+        @Override
         public Traversal<Vertex, Map<String, Number>> 
get_g_V_hasLabelXsoftwareX_group_byXnameX_byXbothE_weight_sumX() {
             return g.V().hasLabel("software").<String, 
Number>group().by("name").by(bothE().values("weight").sum());
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fb05ea79/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/fb05ea79/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

Reply via email to