HyukjinKwon opened a new pull request, #568:
URL: https://github.com/apache/spark-connect-rust/pull/568
### What changes were proposed in this pull request?
A follow-up from a review of #550 (B-5 of the review).
PySpark's `DataFrameReader.jdbc` and `DataFrameWriter.jdbc` pass the
properties as `self.options(**properties)` (`connect/readwriter.py:547`,
`:551`, `:957`). A key that is not a str raises the `TypeError` of that
unpacking, `keywords must be strings`, before any property is set. By then the
reader or writer already has its format, plus the options of a `column` on the
reader or the mode on the writer.
The Python client turned each key into its `str()` and set it as an option
name. So `properties={b"user": "u"}` set an option `b'user'`, and the `user`
property was silently lost; `{1: "v"}` set an option `1`.
Both jdbc methods (`crates/pyspark-rs/src/readwriter.rs`,
`crates/pyspark-rs/src/dataframe.rs`) now:
- raise PySpark's `TypeError` for such a key;
- keep the reader's or writer's settings as PySpark's do;
- set a str key as protobuf takes it (`str_argument`), not through `str()`.
### Why are the changes needed?
To match PySpark 4.3.0. Probed with official pyspark-client 4.3.0 (Python
3.11, protobuf 7.36.2): for the keys `1`, `b"user"` and `None`, and for
`{"user": 1, 2: "x"}`, both jdbc methods raise `TypeError: keywords must be
strings`, and the reader's options stay empty. Ours set the stringified keys
and sent the read.
### Does this PR introduce _any_ user-facing change?
Yes. In the Python client, a jdbc property whose key is not a str raises
PySpark's `TypeError` instead of setting another option name.
### How was this patch tested?
- `test_jdbc_properties_are_keywords_as_pyspark`
(`python/tests/test_dropin_offline.py`, new) covers:
- the reader without and with a `column`, and the writer;
- the keys `1`, `b"user"` and `None`;
- the reader's options after the error;
- that nothing is sent.
It fails without the change (`DID NOT RAISE`).
- The existing jdbc test,
`test_reader_and_writer_check_their_arguments_as_pyspark`, passes.
- `cargo build -p pyspark-rs --release`, `cargo fmt --all --check` and `ruff
check`.
### 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]