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

   ### What changes were proposed in this pull request?
   
   [SPARK-61220](https://issues.apache.org/jira/browse/SPARK-61220): carry the 
thread-local user context extensions to the threads of 
`inheritable_thread_target`, as PySpark does.
   
   - `inheritable_thread_target(session)` now copies the user context 
extensions of the decorating thread, as well as its tags, when it decorates the 
function. Each thread that runs the function is given that copy, as official 
PySpark does: it deep-copies every attribute of `session.client.thread_local` 
and sets them in each thread that runs the function.
   - The copy is shared by the threads of one decoration, as official's is: an 
extension that one of them adds is in the list of all, while one that a thread 
removes or clears is removed for that thread only. Extensions added after the 
decoration are not in the copy.
   - `InheritableThread` takes no extensions, as official's does; that is 
unchanged.
   - Rust: `SparkConnectClient` and `SparkSession` get 
`copy_threadlocal_user_context_extensions` and 
`share_threadlocal_user_context_extensions`, the counterparts of the tag 
functions. PyO3 exposes them as `_copy_thread_user_context_extensions` and 
`_share_thread_user_context_extensions`, used by `pyspark/util.py`.
   
   ### Why are the changes needed?
   
   The decorator copied and shared only the tags. An extension that the 
decorating thread added, such as the pipelines `add_pipeline_analysis_context` 
one, was missing from the requests of the threads that ran the decorated 
function. The reproduction: add a thread-local extension, decorate a function 
with `inheritable_thread_target(spark)`, and read the extensions inside the 
function. The official PySpark 4.3.0 sees 1 extension, this client sees 0.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. The threads that run a function decorated with 
`inheritable_thread_target` now carry the user context extensions of the 
decorating thread in their requests, as PySpark does.
   
   ### How was this patch tested?
   
   - 
`test_inheritable_thread_targets_carry_the_user_context_extensions_as_pyspark` 
(offline, `tests/test_dropin_offline.py`): the requests that the decorated 
threads send carry the extension of the decorating thread, a thread's added 
extension reaches the next thread of the same decoration, a thread's removal 
stays with that thread, a late extension does not reach the threads, and 
`InheritableThread` sends none. Checked against official PySpark 4.3.0 with the 
same sequence: the same extension counts in each thread, and 
`InheritableThread` sees none.
   - `threadlocal_user_context_extensions_of_a_copy_are_shared_as_pyspark` in 
`crates/spark-connect-core/src/client.rs` and in 
`crates/spark-connect/src/session.rs`: the copy and sharing semantics of the 
core client and the session.
   - The lib tests of both crates (660 passed), the build of all tests, also 
with `wasm-udf`, the offline Python suites (2704 passed, 8 skipped), and the 
live drop-in and Arrow suites (224 passed) and live cases (12 passed) against a 
local Spark 4.3.0 server. 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.
   


-- 
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