HyukjinKwon opened a new pull request, #527: URL: https://github.com/apache/spark-connect-rust/pull/527
### What changes were proposed in this pull request? A follow-up of #510 (SPARK-61442), from a review of it (`crates/spark-connect/src/types.rs`): - **JSON reads whitespace after a form with arguments or fields**, as PySpark's `_parse_datatype_json_value` does with its `re.match` patterns, and as this client did before #510: `"string collate UNICODE "`, `"interval day "`, `"interval day to second "`, `"decimal(10,2) "` and the like. A bare name with whitespace after it (`"integer "`, `"interval "`) is still not a type, as in PySpark. - **DDL reads a collation name in backquotes**, in each part of a qualified name too (`` string collate `UTF8_LCASE` ``, `` `system`.`builtin`.`utf8_lcase` ``, also in a struct field with a comment), with a doubled backquote read as one, as Spark's parser unquotes a `multipartIdentifier`. It gives the canonical name that the server gives. An unquoted name is of ASCII letters, digits and underscores only, as Spark's lexer reads it, so `string collate été` is an error of DDL, as it is of the server (JSON keeps PySpark's Unicode `\w+`). - **A bare `time` is no longer a JSON type**: Spark and PySpark name a time in JSON with its precision only (`TimeType().json()` is `"time(6)"`, and PySpark 4.3.0 raises CANNOT_PARSE_DATATYPE for `"time"`). DDL `time` is still `time(6)`, as the server reads it. - **`null` is no longer a DDL type**, as the server's DDL parser rejects it. JSON keeps reading `null`, which Spark's JSON reader accepts for the schemas written before NullType was named `void`; it is now listed in the test as a documented difference from PySpark. `char(n) collate X` and `varchar(n) collate X` stay errors: Spark accepts them, but the Connect protocol's `Char` and `VarChar` carry no collation (the server's own DDL parse of `char(3) collate UNICODE` returns `char(3)`), so reading them would drop the collation silently. ### Why are the changes needed? #510 made both parsers reject trailing whitespace that PySpark and the earlier code accept, and DDL rejected the backquoted collation names that Spark accepts. The test table of #510 also listed two JSON forms that PySpark rejects as forms that both parsers read the same. ### Does this PR introduce _any_ user-facing change? Yes, on unreleased behavior, in `DataType::from_json` / `from_ddl` and in the drop-in's `_parse_datatype_json_string`: the forms above parse, or are errors, as in PySpark 4.3.0 and Spark 4.3.0. ### How was this patch tested? - New rows in `json_and_ddl_parsers_agree_on_the_atomic_and_parameterized_forms`, `from_ddl_unquotes_a_backquoted_collation_name_of_a_field`, and the live `ddl_collations_and_trailing_whitespace_agree_with_the_server_parser` in `crates/spark-connect/tests/types_roundtrip.rs` (run against Spark 4.3.0 servers); `test_json_forms_accept_trailing_whitespace_as_pyspark` and the updated `test_time_types_parse_as_pyspark` in `python/tests/test_dropin_offline.py`. They fail without the change. - `cargo test -p apache-spark-connect --release --lib` (608 passed), `--test types_roundtrip` (offline 22 passed), the `--no-run` builds, the offline drop-in suites (1836 + 110 passed), `cargo fmt --all -- --check`, `ruff check python/tests` and `scripts/audit_no_stubs.sh`. `from_ddl_interval_colon_and_spellings_agree_with_the_server_parser` fails against a local server without `spark.sql.timestampNanosTypes.enabled`, also on master. ### 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]
