HyukjinKwon opened a new pull request, #338: URL: https://github.com/apache/spark-connect-rust/pull/338
### What changes were proposed in this pull request? [SPARK-61148](https://issues.apache.org/jira/browse/SPARK-61148): Leave a builder option of None unset, check the destination of copyFromLocalToFs, and raise NO_ACTIVE_SESSION for the requests of a stopped session, as PySpark does. - Builder options (`config(key, value)`, `config(map=...)`) keep a value of None, and the options are sent with `_set_all`-style pairs without a value, silently. The key stays unset on the session, as with PySpark Connect: `conf.get(key)` raises `SQL_CONF_NOT_FOUND`, `conf.get(key, "unset")` returns the default, and `getAll` does not have the key. A later value of the same key replaces an earlier one. Before, the value was stored as `""`. - `copyFromLocalToFs` raises `AssertionError("destination FS path must be an absolute path.")` for a relative destination, after the scheme and local-file checks and before any request, as `_parse_forward_to_fs_artifacts` does. The core names the artifact `forward_to_fs` + the absolute path (`forward_to_fs/tmp/x`), not `forward_to_fs//tmp/x`. - `stop()` releases the session on the server, then closes the core client. The client is shared by the clones of a session and by its DataFrames, and each of its requests (execute, analyze, config, interrupt, clone, artifacts, fetch error details, release execute) raises a `SparkConnectException` of `NO_ACTIVE_SESSION` once it is closed, as `SparkConnectClient._stub` does. `ReleaseSession` itself is still sent. A session created afterwards, from the builder or with `newSession()`, is unaffected. - A classed Connect error is raised as `SparkConnectException` (it had been `PySparkRuntimeError`; no existing error carries a class). Official PySpark 4.3.0 for the same calls (checked with the reference client against the same server): `config("spark.r12.none", None)` gives `SparkNoSuchElementException SQL_CONF_NOT_FOUND`, and the warning "Failed to set ... to None" is emitted by both; `copyFromLocalToFs("/etc/hosts", "relative/x")` gives `AssertionError destination FS path must be an absolute path.`; after `c.stop()`, `c.range(2).count()`, `c.sql(...)`, `c.conf.get(...)`, `c.version` and `c.cloneSession()` raise `SparkConnectException NO_ACTIVE_SESSION`, and the main session still works. ### Why are the changes needed? - `SparkSession.builder.remote(URL).config("spark.x", None).getOrCreate()` made `spark.conf.get("spark.x")` return `''` and put the key in `getAll`. A common pattern such as `config("spark.x", os.environ.get("X"))` therefore set an empty configuration on the session (for example an empty `spark.sql.session.timeZone`). - `copyFromLocalToFs(local, "relative/out.txt")` reached the server and failed there with `UnsupportedOperationException`, instead of the `AssertionError` that PySpark raises before any request. An absolute destination was named `forward_to_fs//tmp/x`. - After `stop()`, a session kept running its requests on the server and silently reused the released session ID (for example `range(2).count()` returned 2, and `version` returned `4.3.0`), where PySpark raises `NO_ACTIVE_SESSION`. ### Does this PR introduce _any_ user-facing change? Yes. - A builder option of None leaves its key unset instead of setting it to `""`. - A relative `copyFromLocalToFs` destination raises `AssertionError` (`destination FS path must be an absolute path.`) before any request. - A request of a stopped session, or of a DataFrame of it, raises `SparkConnectException` with condition `NO_ACTIVE_SESSION`. - A classed Connect error is a `SparkConnectException` instead of a `PySparkRuntimeError`. ### How was this patch tested? - `test_copy_from_local_to_fs_requires_an_absolute_destination` (offline): the relative destination raises the AssertionError before any request; same as official PySpark 4.3.0. - `test_requests_of_a_stopped_session_raise_no_active_session_as_pyspark` (offline, no server): `count`, `sql().collect()`, `conf.get` and `version` of a stopped `newSession()` raise `SparkConnectException` `NO_ACTIVE_SESSION`; same as official PySpark 4.3.0. - `test_builder_config_none_leaves_the_key_unset_as_pyspark` (live): `config(key, None)`, `config(map={key: None})`; the key is unset (`SQL_CONF_NOT_FOUND`, not in `getAll`), the neighbouring option is set; same as official PySpark 4.3.0. - `test_stopped_session_raises_no_active_session_while_the_others_work` (live): a stopped `newSession()` raises `NO_ACTIVE_SESSION`, and the main session still works; same as official PySpark 4.3.0. - Rust unit tests in `crates/spark-connect/src/session.rs`: `requests_of_a_stopped_session_raise_no_active_session` and `forward_to_fs_artifact_name_is_the_prefix_and_the_absolute_path`. - The tests of both crates, e2e included, against a local Spark 4.3.0 server (877 passed), the build of all tests, also with `wasm-udf`, the offline Python suites (2203 passed, 8 skipped), and the live drop-in, Arrow and ML suites (186 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. -- 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]
