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

   ### What changes were proposed in this pull request?
   
   [SPARK-61155](https://issues.apache.org/jira/browse/SPARK-61155): A 
`foreachBatch` function runs on a Python worker of the server. The worker has 
PySpark and the active session of the query, where a DataFrame that the 
function captures unpickles as PySpark Connect's DataFrame, of that session and 
of its plan.
   
   The client pickles a DataFrame as a function, by value, of its session and 
of the bytes of its relation. On the client, that function rebuilds the 
DataFrame with the Rust client, as before. On a worker without the Rust client, 
it now gives back PySpark Connect's DataFrame of the relation, as it was sent:
   - its plan is a `LogicalPlan` of the relation, of its plan ID, so the 
columns that refer to the DataFrame by that ID resolve against it
   - everything that the function calls there is of PySpark: its own classes 
are made in the function
   
   ### Why are the changes needed?
   
   The function imported the Rust client, which the worker does not have, so a 
`foreachBatch` function that captured a DataFrame failed to start:
   
   ```
   StreamingPythonRunnerInitializationException: 
[STREAMING_PYTHON_RUNNER_INITIALIZATION_FAILURE] ...
   ImportError: cannot import name '_pyspark' from 'pyspark'
   ```
   
   Four tests of Apache Spark's `test_parity_foreach_batch.py` failed on this 
client: `test_accessing_spark_session_through_df`, `test_nested_dataframes`, 
`test_batch_dataframe_join_with_root_session_dataframe_is_unsupported` and 
`test_disabling_fix_restores_root_session_behavior`.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. `foreachBatch` functions that capture DataFrames run, as with PySpark 
4.3.0.
   
   ### How was this patch tested?
   
   - A new live test runs a `foreachBatch` function that captures a filtered 
DataFrame, whose filter refers to the DataFrame by its plan ID, and makes a 
temporary view of it in the session of the query, which the client reads. It 
passes with official PySpark 4.3.0, and fails without this change.
   - The four tests of Apache Spark above run on this client against a local 
server: 3 pass, and `test_disabling_fix_restores_root_session_behavior` fails 
on `StreamingQueryProgress.numInputRows`, which SPARK-61151 fixes.
   - The lib tests of both crates (596 passed), the build of all tests, also 
with `wasm-udf`, the offline Python suites (2212 passed, 8 skipped), and the 
live drop-in and Arrow suites (197 passed) and live cases (10 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