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

    https://github.com/apache/spark/pull/1025#discussion_r14694378
  
    --- Diff: 
core/src/test/scala/org/apache/spark/rdd/PairRDDFunctionsSuite.scala ---
    @@ -83,6 +83,125 @@ class PairRDDFunctionsSuite extends FunSuite with 
SharedSparkContext {
         assert(valuesFor2.toList.sorted === List(1))
       }
     
    +  test("sampleByKey") {
    +    def stratifier (fractionPositive: Double) = {
    +      (x: Int) => if (x % 10 < (10 * fractionPositive).toInt) "1" else "0"
    +    }
    +
    +    def checkSize(exact: Boolean,
    +        withReplacement: Boolean,
    +        expected: Long,
    +        actual: Long,
    +        p: Double): Boolean = {
    +      if (exact) {
    +        return expected == actual
    +      }
    +      val stdev = if (withReplacement) math.sqrt(expected) else 
math.sqrt(expected * p * (1 - p))
    +      // Very forgiving margin since we're dealing with very small sample 
sizes most of the time
    +      math.abs(actual - expected) <= 6 * stdev
    +    }
    +
    +    // Without replacement validation
    +    def takeSampleAndValidateBernoulli(stratifiedData: RDD[(String, Int)],
    +        exact: Boolean,
    +        samplingRate: Double,
    +        seed: Long,
    +        n: Long) = {
    +      val expectedSampleSize = stratifiedData.countByKey().mapValues(count 
=>
    --- End diff --
    
    better merge `.mapValues` to the line below.


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