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

   ### What changes were proposed in this pull request?
   
   A post-merge review of #648 (SPARK-61635) found five gaps between the 
drop-in's type classes and PySpark 4.3.0's. This PR closes them:
   
   1. `StructType`'s errors for its items name the type by its `__name__`, as 
CPython does: `'IntegerType' object has no attribute 'name'`, and 
`'StructField' object is not iterable`. Before, they used the full name, 
`pyspark.sql.types.IntegerType`.
   2. `treeString` prints a nullable flag that was kept as given as PySpark 
prints it, `str(flag).lower()`: `nullable = 0`, `x` or `none`, and 
`containsNull = 1`. Before, it printed the flag's truth. The core crate gets a 
hook for this, `DataType::tree_string_with_flags`, hidden from the docs.
   3. As on PySpark's plain classes, these attributes are assignable: 
`ArrayType.containsNull` and `elementType`, `MapType.keyType`, `valueType` and 
`valueContainsNull`, and `StructType.fields` and `names`. `StructField.name` 
keeps a value that is not a str.
   4. `createDataFrame` of local rows asserts that the nullable flags of its 
schema are bools, as PySpark's converter does (`AssertionError`).
   5. `StructField` is a `DataType` subclass, as in PySpark, so it is accepted 
where a data type is asserted: `StructField("a", StructField(...))`, 
`ArrayType(StructField(...))`, and `StructType().add("a", StructField(...))`. 
Used as a type, it fails where PySpark's client fails:
      - the conversion of local rows 
(`UNSUPPORTED_DATA_TYPE_FOR_ARROW_CONVERSION`);
      - `treeString` (`INVALID_TYPENAME_CALL`);
      - the plan of `DataFrame.to`, `Column.cast`, `try_cast`, and a UDF's 
return type (`UNSUPPORTED_OPERATION`).
   
      `DataFrame.to` raises at the action, as PySpark's plan build does, 
through the deferred plan error of #652.
   
   ### Why are the changes needed?
   
   For parity with PySpark 4.3.0's `pyspark.sql.types`. Each item above was 
checked against the reference client: the classes, the messages, the values 
printed, and when the errors are raised.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, the behaviors above.
   
   Still different from PySpark:
   - Setting `StructField.dataType`, or the element, key or value type, to a 
value that is not a DataType parses a str as DDL and rejects anything else. 
PySpark assigns any value.
   - `StructField.metadata = None` raises `TypeError`.
   - `StructType.fields` and `names` set to a value that is not a list become a 
list.
   - `createDataFrame` asserts no flag for empty data, and none for a truthy 
non-bool `containsNull` of an atomic element. For empty data PySpark sends the 
raw schema JSON, which the server rejects.
   - `Column.cast`, `try_cast` and a UDF's return type raise their 
`UNSUPPORTED_OPERATION` for a StructField type at the call, where PySpark 
raises it at the action, with the same class and message.
   
   ### How was this patch tested?
   
   - New offline tests in `python/tests/test_dropin_offline.py`, one per item, 
each checked to fail without the fix.
   - A new e2e test: the server rejects empty data whose schema uses a 
StructField as a type, as with PySpark.
   - A Rust unit test of the tree string hook.
   - Also passing, with `TZ=UTC`:
     - the offline Python set, including the ML, frequent-pattern and ALS 
offline files: 4453 passed;
     - `test_dropin_e2e.py` against Spark 4.3.0: 292 passed;
     - the Rust lib tests: 683 and 220 passed;
     - the `--no-run` builds, with and without `wasm-udf`;
     - clippy 1.100.0 on the workspace;
     - `cargo fmt`, the stub audit and ruff.
   
   ### 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