HyukjinKwon opened a new pull request, #434: URL: https://github.com/apache/spark-connect-rust/pull/434
### What changes were proposed in this pull request? [SPARK-61308](https://issues.apache.org/jira/browse/SPARK-61308): make `DataType.fromDDL` in the Rust client parse interval ranges, `name:type` fields and type spellings as the server's parser does. - Intervals: only `interval`, `interval <field>` and `interval <from> to <to>` are accepted. A range is in one family (`year to month`, or `day` to `second`) and its end field is later than its start field. Anything else (trailing tokens, `NOT NULL` at type level, unknown or reversed fields, a missing end field) is an `INVALID_DATATYPE_FORMAT` error, where it used to return `CalendarInterval` or a reversed range. - Fields: a top-level colon names a field as a top-level space does, so `a:int`, `x:array<int>` and `x:struct<a:int>` give the same schema as the server. A colon inside brackets or quotes does not. - Spellings: `decimal` is `decimal(10,0)`, `decimal(p)` is `decimal(p,0)`, `dec` and `numeric` are decimal, `real` is float, `character(n)` is `char(n)`, `timestamp_ltz` is `timestamp`, `timestamp without time zone` is `timestamp_ntz`, `timestamp with local time zone` is `timestamp`, `time without time zone` is `time(6)`. `timestamp(6)` is the microsecond timestamp and `timestamp(p)` for p in 7..9 the nanosecond one, as the server gives them. - Python: the drop-in builds the string fragments of `StructType(["a decimal"])` in Rust, so those fragments now accept the same spellings. Official PySpark 4.3.0 has no such constructor, so the `StructType` path is drop-in only. ### Why are the changes needed? `DataType.fromDDL` returned a wrong type where the server raises: `DataType.fromDDL("interval year to second")` and `DataType.fromDDL("interval day to second NOT NULL")` gave `interval`, and `DataType.fromDDL("interval hour to day")` gave a `DayTimeInterval` with a reversed range. The server raises `ParseException` for each. `DataType.fromDDL("a:int")` failed with `INVALID_DATATYPE_FORMAT`, where the server returns `struct<a:int>`. `DataType.fromDDL("decimal")`, `"numeric(10,2)"`, `"real"` and `"timestamp without time zone"` failed where the server accepts them. ### Does this PR introduce _any_ user-facing change? Yes. `DataType.fromDDL` and `StructType.fromDDL` in the Rust client now reject the invalid interval forms and accept the `name:type` form and the spellings above, with the server's types. The drop-in's `StructType(["a decimal"])` fragments accept the same spellings, and `StructType(["a interval year to second"])` raises. ### How was this patch tested? - `from_ddl_interval_ranges_and_colon_fields_as_spark` and `from_ddl_type_spellings_as_spark` (offline, `crates/spark-connect/tests/types_roundtrip.rs`) check the interval forms, the `name:type` forms and the spellings, valid and invalid. They fail on the previous `types.rs` and pass with this change. - `from_ddl_interval_colon_and_spellings_agree_with_the_server_parser` (server-gated) compares the same strings with the server's `parse_ddl`, valid and invalid. - The cases were also run through `DataType.fromDDL` of official PySpark 4.3.0 against the same server: the parse results agree (the `time` and nanosecond rows only differ in the client's own unsupported-type error, which the server's parse does not raise). - `types_roundtrip` (19 passed, with the comparisons against the server's parser) against a local Spark 4.3.0 server. - The lib tests of both crates (678 passed), the build of all tests, also with `wasm-udf`, the offline Python suites (2937 passed, 8 skipped), and the live drop-in and Arrow suites (237 passed) and live cases (14 passed) against a local Spark 4.3.0 server. Clippy reports no diagnostics in the changed lines. ### 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]
