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

   ### What changes were proposed in this pull request?
   
   A follow-up of #152 
([SPARK-60909](https://issues.apache.org/jira/browse/SPARK-60909)), which made 
`spark.sql()` run its statement at once. A review of the last commits found two 
problems with it:
   
   - **Pipeline flow functions:** within a pipeline flow function, 
`spark.sql()` now builds its relation without running the statement, as before 
#152. The server then analyzes the relation in the pipeline once the 
`DefineFlow` defines the flow. PySpark gets the same result by running 
`flow.func()` within a `PipelineAnalysisContext`, in which its server returns 
the relation of `spark.sql()` without running the statement.
     - `SparkConnectGraphElementRegistry.register_flow` enters and leaves a 
flow function around `flow.func()`, through `pipeline_enter_flow_function` and 
`pipeline_exit_flow_function`.
     - The core has a hidden `SparkSession::sql_without_running` for this.
   - **The GIL:** `spark.sql()` now releases it while the statement runs, as 
the other calls that wait for the server do.
   - **Docs:** the Rust `SparkSession::sql_with_references` (#168) now says 
that the server creates each name as a temporary view while the statement runs 
and drops it after, so a name must not be that of a temporary view to keep.
   
   ### Why are the changes needed?
   
   - The registry ran `flow.func()` without a context, as its comment relied on 
`spark.sql()` being lazy. A materialized view whose flow is `spark.sql("SELECT 
* FROM raw")`, with `raw` a view of the same pipeline, failed to register with 
`TABLE_OR_VIEW_NOT_FOUND`, and a statement within a flow function ran for real.
   - While a long statement, such as an `INSERT` or a `CACHE TABLE`, ran, no 
other Python thread could run, not even one that would interrupt it.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes:
   - `spark.sql()` within a pipeline flow function defines the flow of its 
relation, as in PySpark.
   - Other Python threads run while `spark.sql()` runs a statement.
   
   Other requests within a flow function, such as one for the schema of its 
DataFrame, are still sent without the pipeline's analysis context. Sending it, 
as PySpark does as an extension of the user context, needs the user context of 
the requests that #140 adds.
   
   ### How was this patch tested?
   
   - A new offline test, with the mock server, defines a materialized view 
whose flow function calls `spark.sql()`. No `SqlCommand` is sent, the 
`DefineFlow` carries the SQL relation, and a statement outside the flow 
function runs at once again.
   - A new offline test runs `spark.sql()` on another thread against a server 
that holds the statement, and this thread runs meanwhile.
   - Both tests fail before this change.
   - The lib tests and every integration test, e2e included, against the local 
server (643 passed), the build of all tests with `wasm-udf`, the offline Python 
suites (615 passed, 8 live cases skipped), and the live drop-in and Arrow 
suites (57 passed) and live cases (10 passed). 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