HyukjinKwon opened a new pull request, #554:
URL: https://github.com/apache/spark-connect-rust/pull/554
### What changes were proposed in this pull request?
A follow-up of #527 (SPARK-61442), from a review of it. Two fixes to how
`DataType::from_ddl` (`crates/spark-connect/src/types.rs`) reads the collation
of a `string collate <name>`, so that it agrees with Spark's parser:
- **Whitespace around the dots of a qualified name.** Spark's
`multipartIdentifier` reads the parts of `system . builtin . utf8_lcase` across
whitespace, with or without backquotes. `parse_collated_string` took the name
as one whitespace-separated word, so it refused those. It now takes the rest of
the text after `collate`, and `multipart_identifier` skips whitespace around
the dots. A part with whitespace in it that is not in backquotes, such as `sys
tem.builtin.utf8_lcase`, is still refused, as by the server. The JSON form
keeps a single word, as PySpark's `\w+` reads it.
- **ASCII case only.** `parse_single_type` lowercased DDL with
`to_lowercase`. That is a Unicode lowercase, which makes the Kelvin sign
(U+212A) a `k`. So `string collate \u{212A}o` was read as the collation `ko`,
where Spark's lexer, whose unquoted identifiers are of ASCII letters, refuses
it (`INVALID_IDENTIFIER`). It now lowercases with `to_ascii_lowercase`. Spark's
keywords and type names are ASCII, so nothing else changes.
### Why are the changes needed?
To agree with the server, checked against a Spark 4.3.0 server (`SELECT
CAST('a' AS <type>)` and `parse_ddl`):
| DDL | Spark 4.3.0 | `from_ddl` before | after |
|---|---|---|---|
| `string collate system . builtin . utf8_lcase` | `UTF8_LCASE` | error |
`UTF8_LCASE` |
| `` string collate `system` . `builtin` . `utf8_lcase` `` | `UTF8_LCASE` |
error | `UTF8_LCASE` |
| `string collate \u{212A}o` (Kelvin sign) | `INVALID_IDENTIFIER` | `ko` |
error |
| `string collate sys tem.builtin.utf8_lcase` | `PARSE_SYNTAX_ERROR` | error
| error |
### Does this PR introduce _any_ user-facing change?
Yes, on unreleased changes: `DataType::from_ddl` reads those DDL strings as
the server does, also where the Python client parses a DDL schema locally.
### How was this patch tested?
- `json_and_ddl_parsers_agree_on_the_atomic_and_parameterized_forms`
(`crates/spark-connect/tests/types_roundtrip.rs`) now has the qualified names
with whitespace and the Kelvin sign. Its list of strings that neither parser
takes has the part with whitespace in it.
- The live
`ddl_collations_and_trailing_whitespace_agree_with_the_server_parser` now
compares the new cases with the server's `parse_ddl`.
- Both fail without the change and pass with it.
- `cargo test -p apache-spark-connect --release --lib` (622 passed), `--test
types_roundtrip`, the DDL and type-string tests of the offline drop-in suite
(314 passed), `cargo fmt --all -- --check`, and `scripts/audit_no_stubs.sh`.
- Against a local server without `spark.sql.timestampNanosTypes.enabled`,
`from_ddl_interval_colon_and_spellings_agree_with_the_server_parser` fails on
its `timestamp(9)` cases with `FEATURE_NOT_ENABLED`, before and after this
change.
### 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]