Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/916#discussion_r13691081
  
    --- Diff: core/src/main/scala/org/apache/spark/rdd/RDD.scala ---
    @@ -394,20 +402,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 > Int.MaxValue - 1) {
    --- End diff --
    
    The logic needs some cleanup. I think you only need to check whether `num > 
maxSelected`. Otherwise, there is one corner case where `initialCount < 
Int.MaxValue` but `num > maxSelected`.


---
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.
---

Reply via email to