Repository: spark
Updated Branches:
refs/heads/branch-1.2 b3fe6df67 -> e38cb2969
[SPARK-4033][Examples]Input of the SparkPi too big causes the emption exception
If input of the SparkPi args is larger than the 25000, the integer 'n' inside
the code will be overflow, and may be a negative number.
And it causes the (0 until n) Seq as an empty seq, then doing the action
'reduce' will throw the UnsupportedOperationException("empty collection").
The max size of the input of sc.parallelize is Int.MaxValue - 1, not the
Int.MaxValue.
Author: huangzhaowei <[email protected]>
Closes #2874 from SaintBacchus/SparkPi and squashes the following commits:
62d7cd7 [huangzhaowei] Add a commit to explain the modify
4cdc388 [huangzhaowei] Update SparkPi.scala
9a2fb7b [huangzhaowei] Input of the SparkPi is too big
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/89a0990c
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/89a0990c
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/89a0990c
Branch: refs/heads/branch-1.2
Commit: 89a0990c1647f83b5479c3f61bb1ed72adc0bd40
Parents: b3fe6df
Author: huangzhaowei <[email protected]>
Authored: Sun Jan 11 16:32:47 2015 -0800
Committer: Andrew Or <[email protected]>
Committed: Fri Jan 16 09:24:36 2015 -0800
----------------------------------------------------------------------
examples/src/main/scala/org/apache/spark/examples/SparkPi.scala | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/89a0990c/examples/src/main/scala/org/apache/spark/examples/SparkPi.scala
----------------------------------------------------------------------
diff --git a/examples/src/main/scala/org/apache/spark/examples/SparkPi.scala
b/examples/src/main/scala/org/apache/spark/examples/SparkPi.scala
index 9fbb0a8..35b8dd6 100644
--- a/examples/src/main/scala/org/apache/spark/examples/SparkPi.scala
+++ b/examples/src/main/scala/org/apache/spark/examples/SparkPi.scala
@@ -27,8 +27,8 @@ object SparkPi {
val conf = new SparkConf().setAppName("Spark Pi")
val spark = new SparkContext(conf)
val slices = if (args.length > 0) args(0).toInt else 2
- val n = 100000 * slices
- val count = spark.parallelize(1 to n, slices).map { i =>
+ val n = math.min(100000L * slices, Int.MaxValue).toInt // avoid overflow
+ val count = spark.parallelize(1 until n, slices).map { i =>
val x = random * 2 - 1
val y = random * 2 - 1
if (x*x + y*y < 1) 1 else 0
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]