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

   ### What changes were proposed in this pull request?
   
   Two rows of `dev/parity/known-differences.md` are closed: "Metadata of the 
fields of a type" and "The `createDataFrame` of a type of a `UserDefinedType` 
of no JSON".
   
   1. The core held the metadata of a `StructField` as `serde_json` values, so 
a plan and `createDataFrame` of data sent the core's JSON of it:
      - an int of more than 64 bits as a float, so an Arrow-optimized UDF of 
such a return type failed with `ARROW_TYPE_MISMATCH`;
      - a non-finite float raised `ValueError` when the field was made;
      - keys other than str in another order;
      - float ties rounded up (`74334700308107.625` as `...63`, where CPython 
writes `...62`);
      - metadata that `json.dumps` refuses raised when the field was made.
   
      The core now holds the metadata as written: a new `Metadata` type of the 
exact JSON text of each value, with writers of Python's `json.dumps` and of 
`json()`'s sorted, `ensure_ascii` form, and float digits from `ryu`, which 
rounds ties to even as CPython does. Every place that sends a type sends 
PySpark's bytes, with PySpark's errors where it writes them:
      - casts;
      - UDF/UDTF return types;
      - map/apply schemas, whose `NOT_IMPLEMENTED` comes after the AnalyzePlan 
of the columns, as PySpark's;
      - `DataFrame.to`, `from_json`, the readers;
      - `createDataFrame`'s schema (Python's `json()` of the schema, given or 
inferred, also of the metadata of the fields of a UDT's `sqlType()`) and its 
Arrow schemas.
   
      The pandas fast paths strip the metadata of their Arrow schema and name 
their tables by the deduplicated names, as PySpark's pandas path does; the 
duplicate field names of a UDT's SQL type are kept, as PySpark sends them.
   2. `createDataFrame` of a type of a `UserDefinedType` whose `module()` or 
`sqlType()` is not implemented raises PySpark's errors in PySpark's order, 
through PySpark's own conversion of the data: its inference errors first 
(`CANNOT_MERGE_TYPE`, `CANNOT_INFER_TYPE_FOR_FIELD`), then the errors of its 
converters and `serialize`, then those of `json()`.
   
   ### Why are the changes needed?
   
   To close these differences from PySpark (the known-differences review).
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes: the metadata and errors above are PySpark's. The Rust API changes: 
`StructField::metadata` is a `Metadata` (not `Eq`, `Hash`, `Serialize` or 
`Deserialize`, as the `BTreeMap` of `serde_json::Value` was), with its 
accessors. They are in `docs/compatibility.md`'s notes of the 4.4 line. The 
type constructors call a UDT's methods when a field of it is made, where 
PySpark calls none at construction: a new row of 
`dev/parity/known-differences.md`.
   
   ### How was this patch tested?
   
   - New Rust tests of `Metadata`, its writers and the round trips, plus Python 
offline, mock-server and live tests. Each fails without the change.
   - Three rounds of an independent review, which compared the drop-in's 
requests with PySpark 4.3.0's through recording proxies:
     - hundreds of segments across every createDataFrame input kind;
     - property tests over 30,000 metadata dicts and 215,804 doubles;
     - every round's findings were fixed.
   - The core tests (release and debug), wasm, clippy, rustdoc, the stubs, the 
offline suite under coverage, and the live e2e.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code
   
   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