HyukjinKwon opened a new pull request, #436:
URL: https://github.com/apache/spark-connect-rust/pull/436

   ### What changes were proposed in this pull request?
   
   [SPARK-61318](https://issues.apache.org/jira/browse/SPARK-61318): raise the 
exception of a Python progress handler from the execution that called it, as 
PySpark does.
   
   - The Python drop-in's progress handlers now return their exception to the 
Rust execution instead of writing it to `sys.unraisablehook`. The execution 
ends with that error, and the caller of collect(), toPandas(), count() and the 
other executions with progress gets the handler's own exception object. The 
handlers after the failing one are not called for that update.
   - The done call still reaches every handler when the execution ends, as in 
PySpark's `Progress.__exit__`. The release of the execution on the server 
happens before it, as PySpark's generator close does.
   - The core gets `SparkSession::register_fallible_progress_handler`, a new 
method whose handlers return a `Result`. `register_progress_handler` is 
unchanged and wraps its handler. The Rust API gains this method; no signature 
changes.
   - The exception of a done call still goes to `sys.unraisablehook`, since no 
caller is left to raise it to.
   - The recursion bound of nested executions (SPARK-61188) is kept: a 
RecursionError past the bound fails the outer execution as well.
   
   ### Why are the changes needed?
   
   A progress handler that raised, for example an assert in a test harness, was 
silently ignored: the query completed and collect() returned its rows, with a 
traceback on stderr. Repro: a handler that raises ValueError on each non-done 
update, and `spark.sql("SELECT id, reflect('java.lang.Thread', 'sleep', 500L) 
AS s FROM range(0, 4, 1, 4)").collect()`. The drop-in returned the rows. 
PySpark 4.3.0 raises the ValueError from collect(), toPandas() and count(), 
with the same exception object.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. An exception of a Python progress handler now fails the execution that 
called it, and is raised by collect(), toPandas(), count() and the other 
executions with progress, as PySpark does. Rust users gain 
`SparkSession::register_fallible_progress_handler`.
   
   ### How was this patch tested?
   
   - `test_a_progress_handler_that_raises_fails_the_execution_as_pyspark` in 
`python/tests/test_dropin_offline.py` (mock server): the handler's exception is 
raised by collect() as the same object, the handler is called as done, the 
handler after it is not called for that update, nothing goes to 
sys.unraisablehook, and the session works afterwards. The same handler calls 
against the live server, run with PySpark 4.3.0, give the same exception object 
and calls.
   - `test_a_progress_handler_that_raises_fails_the_execution_as_pyspark` in 
`python/tests/test_dropin_e2e.py` (live): collect(), toPandas() and count() 
raise the handler's exception, and a handler that does not raise keeps working. 
The same results as PySpark 4.3.0 against the same server.
   - `test_progress_handler_that_runs_queries_without_end_is_bounded` (offline) 
and 
`test_progress_handler_that_runs_queries_without_end_raises_recursion_error` 
(live) now expect the RecursionError to reach the outer query. PySpark 4.3.0 
instead fails the outer query with a gRPC serialization error at a much deeper 
nesting, so only the propagation is shared. The existing 
`test_progress_handlers_are_called_with_the_progress_of_executions_as_pyspark` 
now expects its raising handler to fail collect() and its done call to go to 
sys.unraisablehook.
   - 
`progress::tests::a_failing_handler_fails_the_update_and_is_still_called_as_done`
 in `crates/spark-connect/src/progress.rs`, inserted before 
`detached_progress_registry_preserves_the_execution_recursion_bound`: the 
update returns the error, the later handler gets only the done call, and the 
registry keeps working. It fails without the change.
   - The lib tests (529 passed), the build of all tests, the offline Python 
suites (2938 passed, 8 skipped) with the rebuilt extension, the new tests also 
under pytest 9.2, the live Rust tests `e2e_integration -k progress` and 
`e2e_session_catalog -k session_progress`, and the live drop-in tests `-k 
progress` (6 passed) against a local Spark 4.3.0 server. Clippy reports no new 
diagnostics in the changed lines.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to