diff options
author | huangzhaowei <carlmartinmax@gmail.com> | 2015-01-11 16:32:47 -0800 |
---|---|---|
committer | Andrew Or <andrew@databricks.com> | 2015-01-11 16:32:47 -0800 |
commit | f38ef6586c2980183c983b2aa14a5ddc1856b7b7 (patch) | |
tree | 8c00ef96be9afe99c10b1b5ecae9263cd69b7997 /examples | |
parent | 6942b974adad396cba2799eac1fa90448cea4da7 (diff) | |
download | spark-f38ef6586c2980183c983b2aa14a5ddc1856b7b7.tar.gz spark-f38ef6586c2980183c983b2aa14a5ddc1856b7b7.tar.bz2 spark-f38ef6586c2980183c983b2aa14a5ddc1856b7b7.zip |
[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 <carlmartinmax@gmail.com>
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
Diffstat (limited to 'examples')
-rw-r--r-- | examples/src/main/scala/org/apache/spark/examples/SparkPi.scala | 4 |
1 files changed, 2 insertions, 2 deletions
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 9fbb0a800d..35b8dd6c29 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 |