Github user mengxr commented on a diff in the pull request:
https://github.com/apache/spark/pull/916#discussion_r13210001
--- Diff: core/src/test/scala/org/apache/spark/rdd/RDDSuite.scala ---
@@ -494,56 +495,84 @@ class RDDSuite extends FunSuite with
SharedSparkContext {
assert(sortedTopK === nums.sorted(ord).take(5))
}
+ test("computeFraction") {
+ // test that the computed fraction guarantees enough datapoints in the
sample with a failure rate <= 0.0001
+ val data = new EmptyRDD[Int](sc)
+ val n = 100000
+
+ for (s <- 1 to 15) {
+ val frac = data.computeFraction(s, n, true)
+ val qpois = new PoissonDistribution(frac * n)
+ assert(qpois.inverseCumulativeProbability(0.0001) >= s, "Computed
fraction is too low")
+ }
+ for (s <- 1 to 15) {
+ val frac = data.computeFraction(s, n, false)
+ val qpois = new PoissonDistribution(frac * n)
+ assert(qpois.inverseCumulativeProbability(0.0001) >= s, "Computed
fraction is too low")
+ }
+ for (s <- List(1, 10, 100, 1000)) {
+ val frac = data.computeFraction(s, n, true)
+ val qpois = new PoissonDistribution(frac * n)
+ assert(qpois.inverseCumulativeProbability(0.0001) >= s, "Computed
fraction is too low")
+ }
+ for (s <- List(1, 10, 100, 1000)) {
+ val frac = data.computeFraction(s, n, false)
+ val qpois = new PoissonDistribution(frac * n)
+ assert(qpois.inverseCumulativeProbability(0.0001) >= s, "Computed
fraction is too low")
+ }
+ }
+
test("takeSample") {
- val data = sc.parallelize(1 to 100, 2)
+ val n = 1000000
+ val data = sc.parallelize(1 to n, 2)
for (num <- List(5, 20, 100)) {
val sample = data.takeSample(withReplacement=false, num=num)
assert(sample.size === num) // Got exactly num elements
assert(sample.toSet.size === num) // Elements are distinct
- assert(sample.forall(x => 1 <= x && x <= 100), "elements not in [1,
100]")
+ assert(sample.forall(x => 1 <= x && x <= n), "elements not in [1,
100]")
--- End diff --
Error messages need to be updated to use `n` instead of `100`.
---
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.
---