Github user mengxr commented on a diff in the pull request:
https://github.com/apache/spark/pull/916#discussion_r13613085
--- Diff: core/src/main/scala/org/apache/spark/rdd/RDD.scala ---
@@ -394,20 +401,22 @@ abstract class RDD[T: ClassTag](
return new Array[T](0)
}
- if (initialCount > Integer.MAX_VALUE - 1) {
- maxSelected = Integer.MAX_VALUE - 1
- } else {
- maxSelected = initialCount.toInt
+ if (!withReplacement && num > initialCount) {
+ throw new IllegalArgumentException("Cannot create sample larger than
the original when " +
+ "sampling without replacement")
}
- if (num > initialCount && !withReplacement) {
- total = maxSelected
- fraction = multiplier * (maxSelected + 1) / initialCount
- } else {
- fraction = multiplier * (num + 1) / initialCount
- total = num
+ if (initialCount > Integer.MAX_VALUE - 1) {
+ val maxSelected = Integer.MAX_VALUE - (5.0 *
math.sqrt(Integer.MAX_VALUE)).toInt
--- End diff --
To be safer, let's change `5.0` to `10.0`. Use `Int.MaxValue` instead of
`Integer.MAX_VALUE`.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---