HyukjinKwon opened a new pull request, #544: URL: https://github.com/apache/spark-connect-rust/pull/544
### What changes were proposed in this pull request? [SPARK-61497](https://issues.apache.org/jira/browse/SPARK-61497): follow-ups of a post-hoc review of SPARK-61475 (#532), checked against PySpark 4.3.0. - **Options of the stream reader** (`crates/pyspark-rs/src/options.rs`, `stream_option_value`): a value is converted with `str_text`, as the batch reader's `coerce_option_value` does. This covers `DataStreamReader.option` and the options of its format methods, including the `path` option that `load()` sends. - **`text()`'s `wholetext`** (`crates/pyspark-rs/src/readwriter.rs`, `crates/pyspark-rs/src/streaming.rs`): - The batch and stream readers' `text` now take PySpark's default `wholetext=False` and set it on every call, as PySpark's `_set_opts` does. An explicit `wholetext=None` is still skipped. - A new `DefaultedOption` (`options.rs`) tells an omitted argument apart from None, as `replace` and `range` already do. - The signatures show `wholetext=False`. ### Why are the changes needed? - **Lossy stream options.** - SPARK-61475 made the stream reader's options the `str()` of their values, through PyO3's lossy `Display`. - So a str that UTF-8 cannot encode was sent as U+FFFD three times, which is another text, for example another path. Such a str is, for example, a lone surrogate from a `surrogateescape`-decoded path. - PySpark raises protobuf's `ValueError`. So do the batch reader, `readStream.options()` and `load(**options)` of the Python client. - **The wholetext default.** - PySpark's `text(paths, wholetext=False, ...)` sets `wholetext` on every call. - So `spark.read.option("wholetext", True).text(path)` reads one row per line in PySpark. The Python client kept the earlier option and read one row per file. - The same holds for `read.options(wholetext="true")` and the stream reader. - `readStream.text(path)` also leaves `wholetext` in the reader's options in PySpark (`{'wholetext': 'False'}`), and left none in the Python client. ### Does this PR introduce _any_ user-facing change? Yes, as in PySpark: - A stream reader option that UTF-8 cannot encode raises `ValueError`. - `text()` overrides an earlier `wholetext` option with its default. ### How was this patch tested? - Offline (`python/tests/test_dropin_offline.py`): - `test_strings_that_utf8_cannot_encode_raise_value_error_as_options_and_fills_as_pyspark` also checks `readStream.option`, `readStream.text(lineSep=...)` and `readStream.format("text").option("path", ...)`. - New `test_text_sets_its_wholetext_default_over_an_earlier_option_as_pyspark`, placed before `test_writer_setters_mutate_and_return_self`. It checks the options of the batch and stream readers after `text()`: with the default, with `wholetext=None` and with `wholetext=True`. It also checks the default `False` of their signatures. - Both fail without the change: `DID NOT RAISE <class 'ValueError'>` and `assert 'true' == 'false'`. - Live, against a local Spark 4.3.0 server, on one file of two lines: - `read.option("wholetext", True).text(d).count()`, `read.options(wholetext="true").text(d).count()`, and the rows of the stream reader's equivalent (availableNow), are 2, 2 and 2, as with PySpark 4.3.0. They were 1, 1 and 1. - The stream reader's surrogate cases raise `ValueError`, as with PySpark. Ours raises at the call, as the batch reader already does; PySpark raises when the plan is serialized. - Checks: - the lib tests of both crates (828 passed); - the build of all tests, also with `wasm-udf` and `datafusion,polars`, without warnings; - `cargo fmt --all --check`, and clippy with no diagnostics on the changed lines; - `ruff check`; - a full trial on master before the merge. ### 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]
