HyukjinKwon opened a new pull request, #739:
URL: https://github.com/apache/spark-connect-rust/pull/739
### What changes were proposed in this pull request?
A follow-up to #672, which deferred a reader's lone-surrogate format and
paths to the plan. A `str` that UTF-8 cannot encode, such as `"a\ud800b"`,
still raised at the call when it was any other string of the readers, the
writers or the session builder. PySpark keeps those strings and fails where it
builds the request that carries them. This PR does the same:
- **Readers** (`spark.read`, `spark.readStream`): an option key or value, a
schema, and the table name of `read.table` and `spark.table` now fail the
DataFrame when its plan is built (`df.schema`, `isStreaming`, an action), and
no request is sent.
- The error is that of the first bad string in the order of PySpark's
plan: the format, the schema, the options, then the paths.
- A later call that unsets or replaces the string removes it, and a copy
or a pickle of the reader keeps it.
- **Writers** (`DataFrameWriter`, `DataFrameWriterV2`): an option, a table
property, the format or provider, and a partitioning, bucketing, sorting or
clustering column are kept. They fail the write action (`save`, `parquet`,
`saveAsTable`, `insertInto`, `create`, `append` and the rest), in PySpark's
order.
- `tableProperty` takes a value of any type, as PySpark's does. bytes are
taken as their UTF-8 text, and another type fails the write with protobuf's
`TypeError`.
- `bucketBy` with a count below 1 does not send its columns, as in
PySpark, so a bad column there does not fail.
- A pickled writer carries the kept entries, so the worker's PySpark
writer fails in the same way.
- **Session builder**: `config` and `appName` keep a key or a value that
does not encode. `getOrCreate` fails with the first of them, as PySpark's
`_set_all` does. A later `config` of the same key replaces it.
- `DataStreamWriter` is unchanged. PySpark sets its request as it goes, so
its setters fail at the call on both clients.
- `docs/compatibility.md` says where each of these fails.
### Why are the changes needed?
So that these calls fail at the same step, with the same error, as on
PySpark. Two kinds of drop-in program depend on it: one that catches the error
around the action, and one that builds a reader or a writer it never uses.
### Does this PR introduce _any_ user-facing change?
Yes, in the Python client:
| Call | Before | After (as PySpark) |
|---|---|---|
| `spark.read.option("k", "a\ud800b")` | `UnicodeEncodeError` at the call |
`.json(p).schema` raises it |
| `spark.table("a\ud800b")` | `UnicodeEncodeError` at the call | `.schema`
raises it |
| `df.write.option("a\ud800b", "v")` | `UnicodeEncodeError` at the call |
`.parquet(p)` raises it |
| `df.writeTo("t").tableProperty("k", 5)` | PyO3's `TypeError` at the call |
`.create()` raises protobuf's `TypeError` |
| `df.writeTo("t").tableProperty("k", b"x")` | PyO3's `TypeError` at the
call | takes it as `"x"` |
| `SparkSession.builder.config("a\ud800b", "v")` | `UnicodeEncodeError` at
the call | `.getOrCreate()` raises it |
### How was this patch tested?
- Probed against the official `pyspark-client` 4.3.0 on a Spark 4.3.0
Connect server. Each probe runs every setter as its own step and then the
action, and records the step that raises and its error. Both clients print the
same output, line for line:
- 108 reader, writer, stream and builder cases;
- 20 `tableProperty` keys and values;
- 38 pickled-writer cases;
- 6 `bucketBy` counts.
- New offline tests in `test_dropin_offline.py`:
-
`test_reader_options_schemas_and_table_names_that_utf8_cannot_encode_fail_the_plan_as_pyspark`;
-
`test_writer_options_and_builder_configs_fail_the_write_or_getOrCreate_as_pyspark`;
- `test_table_property_values_that_are_not_str_fail_the_write_as_pyspark`;
-
`test_stream_reader_strings_that_utf8_cannot_encode_fail_the_plan_as_pyspark`;
- `test_pickled_writers_keep_the_entries_that_fail_their_write_as_pyspark`.
The cases that now defer were removed from the two tests that expected
them to raise at the call.
- The coverage job's whole offline list passed in one run: 5534 passed, 76
skipped (`TZ=UTC`, with protobuf's default upb backend).
- `cargo clippy --workspace --all-targets -- -D warnings`, `cargo fmt
--check`, `ruff check` and `ruff format --check` are clean.
### 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]