Github user andrewor14 commented on a diff in the pull request:
https://github.com/apache/spark/pull/13260#discussion_r64337732
--- Diff: core/src/main/scala/org/apache/spark/rdd/RDD.scala ---
@@ -550,17 +550,19 @@ abstract class RDD[T: ClassTag](
} else {
val fraction = SamplingUtils.computeFractionForSampleSize(num,
initialCount,
withReplacement)
- var samples = this.sample(withReplacement, fraction,
rand.nextInt()).collect()
+ var samples = this.sample(withReplacement, fraction,
rand.nextInt())
+ var count = samples.count()
// If the first sample didn't turn out large enough, keep trying
to take samples;
// this shouldn't happen often because we use a big multiplier
for the initial size
var numIters = 0
- while (samples.length < num) {
+ while (count < num) {
logWarning(s"Needed to re-sample due to insufficient sample
size. Repeat #$numIters")
- samples = this.sample(withReplacement, fraction,
rand.nextInt()).collect()
+ samples = this.sample(withReplacement, fraction,
rand.nextInt())
+ count = samples.count()
numIters += 1
}
- Utils.randomizeInPlace(samples, rand).take(num)
+ Utils.randomizeInPlace(samples.collect(), rand).take(num)
--- End diff --
I think it's important to not have regressions. These samples might be
large, in which case it's worth using a little more memory than doing another
pass.
---
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.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]