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

   ### What changes were proposed in this pull request?
   
   The Python client's `StructType`, `StructField` and `StructType.add` now 
raise the errors that PySpark 4.3.0 raises for the fields, names and data types 
they are given, and keep `nullable`, `containsNull` and `valueContainsNull` as 
given, as PySpark's types keep them:
   
   - `StructType(fields)` reads the `name` of each item first, as PySpark's 
`[f.name for f in fields]` does, then asserts that each item is a 
`StructField`. The drop-in's own convenience of a list of DDL strings 
(`StructType(["a int"])`) is removed, since PySpark rejects it.
   - `StructField(name, dataType, ...)` asserts the data type first, then the 
name.
   - `StructType.add` asserts the data type and then the name, as `StructField` 
does. It raises `ARGUMENT_REQUIRED` only for a str name without a data type.
   - The nullable flags are kept as given: a non-bool value is accepted, and 
`jsonValue`, `json`, `repr`, equality and pickling show it as PySpark does. The 
plan uses its truth.
   - The message for a bad type string keeps the detail of 
`INVALID_DATATYPE_FORMAT`.
   
   ### Why are the changes needed?
   
   For parity with PySpark 4.3.0. Before, each call below raised a different 
error than PySpark:
   
   | Call | Before (drop-in) | After, as PySpark 4.3.0 |
   |---|---|---|
   | `StructType(["a"])` | `ValueError` with a Rust Debug dump | 
`AttributeError: 'str' object has no attribute 'name'` |
   | `StructType("a int")` | `TypeError: Can't extract str to Vec` | the same 
`AttributeError` |
   | `StructType([("a", IntegerType())])` | an invented `TypeError` | 
`AttributeError: 'tuple' object has no attribute 'name'` |
   | `StructField(5, IntegerType())` | `TypeError: 'int' object is not an 
instance of 'str'` | `AssertionError: field name 5 should be a string` |
   | `StructField(5, "int")` | the name error | `AssertionError: dataType int 
should be an instance of <class 'pyspark.sql.types.DataType'>` |
   | `StructType().add("g", 5)` | `TypeError: expected a DataType or a DDL type 
string` | `AssertionError: dataType 5 should be an instance of ...` |
   | `StructField("g", IntegerType(), 1)` | `TypeError` | accepted; `nullable` 
is `1` |
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes:
   - The calls above raise PySpark's errors.
   - Non-bool nullable flags are accepted and kept.
   - `StructType` no longer accepts a list of DDL strings, which PySpark 
rejects too.
   
   ### How was this patch tested?
   
   - New offline tests in `python/tests/test_dropin_offline.py`, for the 
fields, names and data types, `add`, and the kept flags. The test of the bad 
type string message is updated for its detail. Each new or updated test was 
checked to fail without the fix (6 failures).
   - Also passing, with `TZ=UTC`:
     - CI's offline Python set;
     - `test_dropin_e2e.py` against Spark 4.3.0: 279 passed;
     - the Rust lib tests and the `--no-run` builds;
     - `cargo fmt`, the stub audit and ruff.
   
   Not changed here:
   - `treeString` prints the truth of a non-bool flag, where PySpark prints the 
value as given. It comes from the core crate.
   - Local data in `createDataFrame` is not asserted to have bool flags, as 
PySpark's conversion asserts.
   
   ### 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