HyukjinKwon opened a new pull request, #559:
URL: https://github.com/apache/spark-connect-rust/pull/559

   ### What changes were proposed in this pull request?
   
   The batch readers and writers of the Python client, and 
`DataStreamWriter.start`, now set the settings of a call (the format, the 
options, the schema, the mode, `partitionBy`, the query name) before they check 
its path, as PySpark does. So a call whose path is not a str keeps them on the 
reader or writer.
   
   - Writers: `save` and `parquet`/`json`/`csv`/`orc`/`text`/`xml` of 
`DataFrameWriter` and `DataStreamWriter.start` take the path as any object, and 
check it after the settings are on the writer. A path that is not a str raises 
the `TypeError` that PySpark's default protobuf backend (upb) raises for it, 
"bad argument type for built-in operation".
   - Readers: `text`, `parquet`, `orc`, `load`, and the str or list branch of 
`json`/`csv`/`xml`, put the format and the options (and, for `load`, the 
schema) on the reader before the path is checked. `json` and `xml` keep their 
options when the path is of another type, and `xml` keeps its schema, as 
PySpark's do.
   
   ### Why are the changes needed?
   
   PySpark sets the settings first and fails at the path. The drop-in checked 
the path while it extracted the arguments, before any setting, so a call that 
failed kept none of them, and the next call of the same writer or reader 
differed:
   
   ```python
   w = spark.range(1).write.option("compression", "gzip")
   try:
       w.json(123)
   except TypeError:
       pass
   w.mode("overwrite").save(path)   # PySpark 4.3.0 writes json.gz; before this 
change: snappy Parquet
   
   q = spark.readStream.format("rate").load().writeStream
   try:
       q.start(123, format="memory", queryName="q")
   except TypeError:
       pass
   q.start()   # PySpark starts the memory query "q"; before: 
[_LEGACY_ERROR_TEMP_2047] 'path' is not specified
   
   r = spark.read.option("wholetext", True)
   try:
       r.text(123)
   except AssertionError:
       pass
   # PySpark: r._options == {'wholetext': 'false'}, r._format == 'text'; 
before: unchanged
   ```
   
   A path that UTF-8 cannot encode keeps raising the `UnicodeEncodeError` of 
upb, as PySpark does, and is not changed here. This is a follow-up of 
SPARK-61057 (#547), whose stream reader already keeps its settings. The writer 
side was found by another review.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. After a call whose path is not a str fails, the next call of the same 
reader or writer uses its settings, as in PySpark. The `TypeError` of a writer 
or stream `start` path that is not a str now has PySpark's (upb) message.
   
   ### How was this patch tested?
   
   - Four new offline tests in `python/tests/test_dropin_offline.py`, which 
fail without the change: the error of a path that is not a str (int, float, 
list) for every writer method and stream `start`, and the settings that the 
readers, the writers and the stream writer keep after such a call.
   - Probes of the reference client under upb and of this one: the same first 
error, class and message, for every writer method and stream `start` with an 
int, float, `pathlib.Path` or list path; the same result for a later 
`save`/`start` (json.gz, csv, snappy Parquet, zstd ORC, a memory query); the 
same reader state.
   - The offline suite (1906 passed) and `test_dropin_e2e.py` against a Spark 
4.3.0 server (271 passed) under upb, the Rust library tests, the `--no-run` 
builds (with and without `wasm-udf`), `cargo fmt --check`, 
`scripts/audit_no_stubs.sh` and the ruff gates.
   
   ### 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]

Reply via email to