-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-50520][PySpark] Respect timeout in df.rdd.countApprox() #56060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4843,7 +4843,8 @@ def sumApprox( | |
| jrdd = self.mapPartitions(lambda it: [float(sum(it))])._to_java_object_rdd() | ||
| assert self.ctx._jvm is not None | ||
| jdrdd = self.ctx._jvm.JavaDoubleRDD.fromRDD(jrdd.rdd()) | ||
| r = jdrdd.sumApprox(timeout, confidence).getFinalValue() | ||
| partial = jdrdd.sumApprox(timeout, confidence) | ||
| r = partial.initialValue() | ||
| return BoundedFloat(r.mean(), r.confidence(), r.low(), r.high()) | ||
|
|
||
| def meanApprox( | ||
|
|
@@ -4881,7 +4882,8 @@ def meanApprox( | |
| jrdd = self.map(float)._to_java_object_rdd() | ||
| assert self.ctx._jvm is not None | ||
| jdrdd = self.ctx._jvm.JavaDoubleRDD.fromRDD(jrdd.rdd()) | ||
| r = jdrdd.meanApprox(timeout, confidence).getFinalValue() | ||
| partial = jdrdd.meanApprox(timeout, confidence) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking: this |
||
| r = partial.initialValue() | ||
| return BoundedFloat(r.mean(), r.confidence(), r.low(), r.high()) | ||
|
|
||
| def countApproxDistinct(self: "RDD[T]", relativeSD: float = 0.05) -> int: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix here is correct, but it's incomplete:
meanApprox(line 4885) is the direct peer ofsumApprox-- sameJavaDoubleRDDapproximate action returning aPartialResult[BoundedDouble]-- yet it still calls.getFinalValue(), which blocks until the entire job finishes (PartialResult.getFinalValuewaits untilsetFinalValue, fired only when all tasks complete). SomeanApprox(timeout=...)retains the exact bug this PR fixes forsumApprox/countApprox, and the two parallel paths now diverge.The PR description frames the problem generically ("PySpark approximate RDD actions currently call getFinalValue() ..."), which reads as covering all three actions. Suggest applying the same change to
meanApprox:(this suggestion is for line 4885, shown here for reference). If
meanApproxis intentionally out of scope, please narrow the PR description to say so explicitly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review.
I've updated
meanApproxto use the same timeout-aware handling assumApproxby switching fromgetFinalValue()toinitialValue().I also updated the regression test to use a deliberately slow workload so that the timeout behavior is observable. The previous version could complete quickly even with the blocking implementation and therefore did not reliably detect the regression.
Additionally, the test now cleans up the background approximate job before proceeding to avoid interference with subsequent tests.
Verified with: python/run-tests.py --testnames pyspark.tests.test_rdd