HyukjinKwon opened a new pull request, #547:
URL: https://github.com/apache/spark-connect-rust/pull/547
### What changes were proposed in this pull request?
A follow-up of #266 (SPARK-61057), from a review of #544 (SPARK-61497),
which rewrote `text()`.
The format readers of the Python client's `DataStreamReader` are `csv`,
`json`, `orc`, `parquet`, `text` and `xml`
(`crates/pyspark-rs/src/streaming.rs`). They set their format on the reader
before they checked that `path` is a str, so a `NOT_EXPECTED_TYPE` of `path`
left the reader with their format. PySpark's set their options, then raise
`NOT_EXPECTED_TYPE` for a path that is not a str, before they call
`load(path=path, format=...)`, which sets the format
(pyspark/sql/connect/streaming/readwriter.py:130-157 and the format readers).
So the reader keeps the format it had.
The check is now one method, `PyDataStreamReader::format_path`:
- the reader takes the options of the call;
- a path that is not a str is `NOT_EXPECTED_TYPE`;
- then the reader takes the format, and the path is checked as `load` checks
it, so `VALUE_NOT_NON_EMPTY_STR` of an empty path still leaves the format, as
in PySpark.
### Why are the changes needed?
To match PySpark 4.3.0, and so that a later `load()` of the reader reads the
format it was given:
```python
r = spark.readStream.format("rate")
r.json(123) # PySparkTypeError: NOT_EXPECTED_TYPE, in both clients
r._format # PySpark 4.3.0: 'rate'; this client before: 'json'
```
The same applies to the six readers, from a reader with no format (PySpark:
`None`) and from one with a format, as checked with the Connect client of
official PySpark 4.3.0. An empty path (`" "`) leaves the reader's format, as
in PySpark. The options of the call stay on the reader, as before.
### Does this PR introduce _any_ user-facing change?
Yes, on unreleased changes. In the Python client, a stream format reader
called with a path that is not a str no longer changes the reader's format.
### How was this patch tested?
-
`test_stream_format_readers_set_their_format_for_a_str_path_only_as_pyspark` in
`python/tests/test_dropin_offline.py`, new. For the six readers, a path that is
not a str, from no format and from a format, and an empty path. Also the
options that `text()` leaves. It fails on an extension built from master and
passes with the change. Every expected value was checked with official PySpark
4.3.0.
- The offline drop-in and ML suites (`tests/test_dropin_offline.py
tests/test_ml_offline.py`), `cargo build -p pyspark-rs --release`, `cargo fmt
--all -- --check`, `ruff check` and `ruff format --check`, and
`scripts/audit_no_stubs.sh`.
### 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]