Commit c4bb486
[SPARK-27992][SPARK-28881][PYTHON][2.4] Allow Python to join with connection thread to propagate errors
### What changes were proposed in this pull request?
This PR proposes to backport #24834 with minimised changes, and the tests added at #25594.
#24834 was not backported before because basically it targeted a better exception by propagating the exception from JVM.
However, actually this PR fixed another problem accidentally (see #25594 and [SPARK-28881](https://issues.apache.org/jira/browse/SPARK-28881)). This regression seems introduced by #21546.
Root cause is that, seems
https://github.com/apache/spark/blob/23bed0d3c08e03085d3f0c3a7d457eedd30bd67f/sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala#L3370-L3384
`runJob` with `resultHandler` seems able to write partial output.
JVM throws an exception but, since the JVM exception is not propagated into Python process, Python process doesn't know if the exception is thrown or not from JVM (it just closes the socket), which results as below:
```
./bin/pyspark --conf spark.driver.maxResultSize=1m
```
```python
spark.conf.set("spark.sql.execution.arrow.enabled",True)
spark.range(10000000).toPandas()
```
```
Empty DataFrame
Columns: [id]
Index: []
```
With this change, it lets Python process catches exceptions from JVM.
### Why are the changes needed?
It returns incorrect data. And potentially it returns partial results when an exception happens in JVM sides. This is a regression. The codes work fine in Spark 2.3.3.
### Does this PR introduce any user-facing change?
Yes.
```
./bin/pyspark --conf spark.driver.maxResultSize=1m
```
```python
spark.conf.set("spark.sql.execution.arrow.enabled",True)
spark.range(10000000).toPandas()
```
```
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/.../pyspark/sql/dataframe.py", line 2122, in toPandas
batches = self._collectAsArrow()
File "/.../pyspark/sql/dataframe.py", line 2184, in _collectAsArrow
jsocket_auth_server.getResult() # Join serving thread and raise any exceptions
File "/.../lib/py4j-0.10.7-src.zip/py4j/java_gateway.py", line 1257, in __call__
File "/.../pyspark/sql/utils.py", line 63, in deco
return f(*a, **kw)
File "/.../lib/py4j-0.10.7-src.zip/py4j/protocol.py", line 328, in get_return_value
py4j.protocol.Py4JJavaError: An error occurred while calling o42.getResult.
: org.apache.spark.SparkException: Exception thrown in awaitResult:
...
Caused by: org.apache.spark.SparkException: Job aborted due to stage failure: Total size of serialized results of 1 tasks (6.5 MB) is bigger than spark.driver.maxResultSize (1024.0 KB)
```
now throws an exception as expected.
### How was this patch tested?
Manually as described above. unittest added.
Closes #25593 from HyukjinKwon/SPARK-27992.
Lead-authored-by: HyukjinKwon <[email protected]>
Co-authored-by: Bryan Cutler <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>1 parent 0d0686e commit c4bb486
File tree
4 files changed
+72
-5
lines changed- core/src/main/scala/org/apache/spark/api/python
- python/pyspark/sql
- sql/core/src/main/scala/org/apache/spark/sql
4 files changed
+72
-5
lines changedLines changed: 37 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
440 | 440 | | |
441 | 441 | | |
442 | 442 | | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
443 | 466 | | |
444 | 467 | | |
445 | 468 | | |
| |||
957 | 980 | | |
958 | 981 | | |
959 | 982 | | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2175 | 2175 | | |
2176 | 2176 | | |
2177 | 2177 | | |
2178 | | - | |
2179 | | - | |
2180 | | - | |
| 2178 | + | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
| 2183 | + | |
| 2184 | + | |
2181 | 2185 | | |
2182 | 2186 | | |
2183 | 2187 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| |||
4550 | 4550 | | |
4551 | 4551 | | |
4552 | 4552 | | |
| 4553 | + | |
| 4554 | + | |
| 4555 | + | |
| 4556 | + | |
| 4557 | + | |
| 4558 | + | |
| 4559 | + | |
| 4560 | + | |
| 4561 | + | |
| 4562 | + | |
| 4563 | + | |
| 4564 | + | |
| 4565 | + | |
| 4566 | + | |
| 4567 | + | |
| 4568 | + | |
| 4569 | + | |
| 4570 | + | |
| 4571 | + | |
| 4572 | + | |
| 4573 | + | |
| 4574 | + | |
| 4575 | + | |
| 4576 | + | |
| 4577 | + | |
| 4578 | + | |
4553 | 4579 | | |
4554 | 4580 | | |
4555 | 4581 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3284 | 3284 | | |
3285 | 3285 | | |
3286 | 3286 | | |
3287 | | - | |
| 3287 | + | |
3288 | 3288 | | |
3289 | 3289 | | |
3290 | 3290 | | |
| |||
0 commit comments