Repository navigation
[SPARK-61153][CONNECT][PYTHON] Run the queries of progress handlers and hooks, and keep an execution reattachable when a hook adds reattach options, as PySpark does - #342
Closed
HyukjinKwon wants to merge 1 commit into
Conversation
…nd hooks, and keep an execution reattachable when a hook adds reattach options, as PySpark does A progress handler or a session hook runs while an execution runs, so a query it runs blocked the runtime from within itself and panicked with "Cannot start a runtime from within a runtime". block_on now blocks in place on a multi-thread runtime, as the nested query needs the runtime's context to be left. The reattachable iterator also always appends its reattachable option after the hooks ran, as PySpark does, so a hook that adds reattachable = False no longer makes the execution fail with OPERATION_NOT_FOUND. Co-authored-by: Isaac <no-reply@databricks.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
SPARK-61153: a query run inside a progress handler or a
SparkSession.Hookruns, and a hook that addsreattachable = Falsekeeps the execution reattachable, as PySpark does.spark_connect_core::runtime::block_onblocks in place when it is called from a thread that is already in the shared multi-thread runtime's context, which is the case for a callback that runs inside an execution. The nested query then runs, as it does in PySpark. On acurrent_threadruntime the call still fails as before, since such a runtime cannot block in place. No lock is held across the callback: the progress handlers and the hook are cloned out of their locks before they are called.ExecutePlanResponseReattachableIterator::newalways appends itsreattachable = Trueoption, after the request options that the hooks added, as PySpark'sExecutePlanResponseReattachableIteratordoes. Before, it appended the option only when the request had none, so a hook'sreattachable = Falsemade the server treat the execution as not reattachable, and the rows were lost withINVALID_HANDLE.OPERATION_NOT_FOUND.current_threadruntime, which keeps the panic they check: the schema cache of a dataframe and the version cache of a session.Why are the changes needed?
Both defects run Python callbacks while an execution runs:
Official PySpark 4.3.0 gives
nested count in handler -> 4,outer -> [Row(t=1999999000000)],outer hook query -> 3, and(2, [Row(x=1)])for the last case.Does this PR introduce any user-facing change?
Yes. A query run in a progress handler or a session hook returns its result instead of panicking, and a hook that appends a non-reattachable option no longer fails the execution.
How was this patch tested?
test_block_on_nested_in_block_onandtest_block_on_nested_on_a_worker_threadinruntime.rs: ablock_onfrom withinblock_on, and from a worker thread.test_reattach_options_set_after_a_hook_added_a_false_oneinreattach.rs: the iterator's options are[false, true]after a hook addedfalse.test_progress_handler_runs_a_query_of_its_own_as_pyspark: a handler runs a count while the execution runs. The same results with official PySpark 4.3.0.test_hook_runs_a_query_of_its_own_as_pyspark: a hook runs a query. The same results with official PySpark 4.3.0.test_hook_appending_a_non_reattachable_option_keeps_the_execution_reattachable: a count and asqlcollect with a hook that appendsreattachable = False. The same results with official PySpark 4.3.0.wasm-udf, the offline Python suites (2201 passed, 8 skipped), and the live drop-in, Arrow and ML suites (187 passed) and live cases (10 passed). rustfmt passes, and clippy reports no diagnostics in the changed lines.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.