HyukjinKwon opened a new pull request, #462: URL: https://github.com/apache/spark-connect-rust/pull/462
### What changes were proposed in this pull request? [SPARK-61342](https://issues.apache.org/jira/browse/SPARK-61342): the exception of the done call of a progress handler is raised from the execution, as PySpark raises it. - Core (`crates/spark-connect/src/progress.rs`): - `ProgressTracker::finish` makes the done call once. - `ExecutionStream::message` calls it when the stream ends, and when it fails (the stream, the update of a handler, or the chunks of a batch). - `SparkSession::execute_plan` calls it when the execution fails to start. - Its error is the error of the execution, and replaces the execution's own error, as the exception of PySpark's `Progress.__exit__` does. - An execution dropped before its end (an iterator its caller stopped reading) still gets its done call on drop. Its error has no caller left, so it goes to the new `spark_connect::progress::set_unreturned_error_handler`; an error that a done error replaced goes there too. - The drop-in (`crates/pyspark-rs/src/progress.rs`): - returns the done-call exception like any other, to be raised from the execution; - installs a handler that reports a dropped execution's exception to `sys.unraisablehook`, as PySpark's generator does; - releases a replaced one, which PySpark keeps as the `__context__` of the one it raises. - Executions that PySpark runs without a `Progress` no longer call the handlers: - the registrations of functions, table functions, data sources and Java functions (its `_execute`), through the new `execute_command_unreported`; - pipeline runs (its `execute_command_as_iterator`); - the drop-in's removal of a server listener before a new add, which PySpark does not send. - `register_fallible_progress_handler` documents the done-call error. ### Why are the changes needed? When a progress handler raised on its done call, the drop-in returned the result of the execution and sent the exception to `sys.unraisablehook`. That happened for collect, toPandas, toArrow, toLocalIterator, count, first, isEmpty, show, writes, spark.sql, catalog calls and foreachPartition. PySpark 4.3.0 raises it from all of them: - Its done call is made in `Progress.__exit__`, inside the `with` of the execution (`_execute_and_fetch` and `to_table_as_iterator` of `client/core.py`). - So the exception goes out of the call, and replaces the execution's error when there is one. The Rust API dropped the done-call error of a fallible handler. ### Does this PR introduce _any_ user-facing change? Yes: - A progress handler that raises on its done call now fails the execution with its exception, as in PySpark, and it replaces the execution's own error. - The registrations of functions, table functions, data sources and Java functions, and pipeline runs, no longer call the progress handlers, as in PySpark. - In the Rust API, `set_unreturned_error_handler` and `UnreturnedError` are new. ### How was this patch tested? - Offline (`python/tests/test_dropin_offline.py`): `test_the_exception_of_a_done_call_fails_the_execution_as_pyspark`. - The done exception goes out of collect and toLocalIterator (with and without prefetch), and not to `sys.unraisablehook`. - It replaces the error of an execution that fails. - A UDF registration makes no handler call. - The existing test that asserted the unraisable done exception now asserts the raise. - Both fail without the change. - Live (`python/tests/test_dropin_e2e.py`): `test_the_exception_of_a_done_call_fails_the_execution_as_pyspark`. It fails without the change. - Rust (`progress.rs`): `the_error_of_the_done_call_is_the_error_of_the_execution`. - `finish` calls once, and its error replaces the execution's. - A tracker dropped before its end hands its error over. - The reviewer's probes against official PySpark 4.3.0 now match, apart from the number of progress updates, which depends on server timing: - the done exception on 16 entry points, both modes; - no done call for the registrations; - an iterator closed early. - Checks: - lib tests of both crates (717 passed); - the build of all tests (also `wasm-udf`, `datafusion,polars`) without warnings; - `cargo fmt --all --check`, and clippy with no diagnostics on the changed lines; - the offline Python suites (2980 passed, 8 skipped); - the live drop-in, Arrow and ML suites against a local Spark 4.3.0 server (255 passed). ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Opus 5.5 This pull request and its description were written by Isaac. -- 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]
