This is an automated email from the ASF dual-hosted git repository.
HyukjinKwon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark-connect-rust.git
The following commit(s) were added to refs/heads/master by this push:
new d52f418d [SPARK-61442][CONNECT][FOLLOWUP] Read whitespace around the
dots of a qualified collation name, and only ASCII case, in DDL as Spark's
parser does
d52f418d is described below
commit d52f418d516b1121be682bfa4feace7a8064ba25
Author: Hyukjin Kwon <[email protected]>
AuthorDate: Thu Nov 12 18:22:51 2026 +0900
[SPARK-61442][CONNECT][FOLLOWUP] Read whitespace around the dots of a
qualified collation name, and only ASCII case, in DDL as Spark's parser does
### 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 [...]
- **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.
Closes #554 from HyukjinKwon/SPARK-61442-followup-collation-dots.
Authored-by: Hyukjin Kwon <[email protected]>
Signed-off-by: Hyukjin Kwon <[email protected]>
---
crates/spark-connect/src/types.rs | 32 ++++++++++++++++++---------
crates/spark-connect/tests/types_roundtrip.rs | 23 ++++++++++++++++++-
2 files changed, 43 insertions(+), 12 deletions(-)
diff --git a/crates/spark-connect/src/types.rs
b/crates/spark-connect/src/types.rs
index a090c3c4..062c5b15 100644
--- a/crates/spark-connect/src/types.rs
+++ b/crates/spark-connect/src/types.rs
@@ -1801,18 +1801,23 @@ fn interval_field(name: &str, fields: &[(&str, i32)])
-> Option<i32> {
/// In JSON the name is of the letters of any script, as the `\w+` of PySpark's
/// `_STRING_WITH_COLLATION` reads them, and the collation is the name as it
is written, as
/// PySpark's `StringType(name)` keeps it. In DDL the name is a multipart
identifier of ASCII
-/// letters, digits and underscores, as Spark's lexer reads an unquoted one,
and each of its parts
-/// may be in backquotes (see [`multipart_identifier`]). The collation is the
name in the canonical
+/// letters, digits and underscores, as Spark's lexer reads an unquoted one,
each of its parts may
+/// be in backquotes, and its dots may have whitespace around them (see
[`multipart_identifier`]).
+/// Its keywords and unquoted parts are read in ASCII lowercase, so a letter
outside ASCII, such
+/// as the Kelvin sign, is not taken for an ASCII one. The collation is the
name in the canonical
/// form that the server gives it (see [`canonical_collation_name`]), which
may be qualified as
/// `system.builtin.<name>`, as Spark's
`CollationFactory.resolveFullyQualifiedName` reads it.
fn parse_collated_string(s: &str, grammar: TypeStringGrammar) ->
Result<DataType> {
let invalid = || invalid_type_string(s, "collated string type");
- let words: Vec<&str> = s.split_whitespace().collect();
- let ["string", "collate", name] = words[..] else {
- return Err(invalid());
- };
+ let name = s
+ .strip_prefix("string")
+ .and_then(|rest| rest.trim_start().strip_prefix("collate"))
+ .filter(|rest| rest.starts_with(char::is_whitespace))
+ .map(str::trim)
+ .ok_or_else(invalid)?;
let parts = match grammar {
- TypeStringGrammar::Json => vec![name.to_string()],
+ TypeStringGrammar::Json if !name.contains(char::is_whitespace) =>
vec![name.to_string()],
+ TypeStringGrammar::Json => return Err(invalid()),
TypeStringGrammar::Ddl =>
multipart_identifier(name).ok_or_else(invalid)?,
};
let name = match parts.as_slice() {
@@ -1840,12 +1845,14 @@ fn parse_collated_string(s: &str, grammar:
TypeStringGrammar) -> Result<DataType
}
/// The parts of the multipart identifier `name` of DDL, as Spark's
`multipartIdentifier` reads
-/// it: parts separated by dots, each of them either as it is written or in
backquotes, where a
-/// doubled backquote is one backquote. `None` if `name` is malformed.
+/// it: parts separated by dots, with any whitespace around them, each of them
either as it is
+/// written or in backquotes, where a doubled backquote is one backquote.
`None` if `name` is
+/// malformed, such as a part with whitespace in it that is not in backquotes.
fn multipart_identifier(name: &str) -> Option<Vec<String>> {
let mut parts = Vec::new();
let mut chars = name.chars().peekable();
loop {
+ while chars.next_if(|c| c.is_whitespace()).is_some() {}
let mut part = String::new();
if chars.next_if_eq(&'`').is_some() {
loop {
@@ -1856,10 +1863,11 @@ fn multipart_identifier(name: &str) ->
Option<Vec<String>> {
}
}
} else {
- while let Some(c) = chars.next_if(|c| *c != '.') {
+ while let Some(c) = chars.next_if(|c| *c != '.' &&
!c.is_whitespace()) {
part.push(c);
}
}
+ while chars.next_if(|c| c.is_whitespace()).is_some() {}
parts.push(part);
match chars.next() {
Some('.') => {}
@@ -2374,7 +2382,9 @@ fn complex_type_inner<'a>(input: &'a str, keyword: &str,
detail: &str) -> Result
/// Parse a single type (primitive or complex)
fn parse_single_type(input: &str) -> Result<DataType> {
- let trimmed = canonical_type_spelling(&input.trim().to_lowercase());
+ // ASCII only, as Spark's lexer, whose keywords and unquoted identifiers
are of ASCII letters:
+ // a lowercase of the letters of any script would read the Kelvin sign as
a `k`.
+ let trimmed = canonical_type_spelling(&input.trim().to_ascii_lowercase());
// Complex types
if after_complex_keyword(input, "array").is_some() {
diff --git a/crates/spark-connect/tests/types_roundtrip.rs
b/crates/spark-connect/tests/types_roundtrip.rs
index 7a7b91c4..fa7395b3 100644
--- a/crates/spark-connect/tests/types_roundtrip.rs
+++ b/crates/spark-connect/tests/types_roundtrip.rs
@@ -1097,6 +1097,9 @@ fn
ddl_collations_and_trailing_whitespace_agree_with_the_server_parser() {
"string collate `UTF8_LCASE`",
"string collate `system`.`builtin`.`utf8_lcase`",
"string collate `system`.builtin.`utf8_lcase`",
+ "string collate system . builtin . utf8_lcase",
+ "string collate `system` . `builtin` . `utf8_lcase`",
+ "string collate ko",
"string collate UNICODE ",
"time",
] {
@@ -1111,6 +1114,8 @@ fn
ddl_collations_and_trailing_whitespace_agree_with_the_server_parser() {
"string collate `été`",
"string collate été",
"string collate `system.builtin.utf8_lcase`",
+ "string collate \u{212A}o",
+ "string collate sys tem.builtin.utf8_lcase",
"null",
] {
assert!(session.parse_ddl(ddl).is_err(), "{ddl}");
@@ -1399,6 +1404,8 @@ fn
json_and_ddl_parsers_agree_on_the_atomic_and_parameterized_forms() {
"string collate `system`.`builtin`",
"string collate `system.builtin.utf8_lcase`",
"string collate `system`.`builtin`.`utf8_lcase`.`x`",
+ "string collate sys tem.builtin.utf8_lcase",
+ "string collate system . . utf8_lcase",
"char(5) collate UNICODE",
// Not a type.
"",
@@ -1479,10 +1486,24 @@ fn
json_and_ddl_parsers_agree_on_the_atomic_and_parameterized_forms() {
Some(string("UTF8_LCASE")),
),
("string collate `UNICODE`", None, Some(string("UNICODE"))),
+ // As Spark's `multipartIdentifier`, the dots of a qualified name may
have whitespace around
+ // them in DDL.
+ (
+ "string collate system . builtin . utf8_lcase",
+ None,
+ Some(string("UTF8_LCASE")),
+ ),
+ (
+ "string collate `system` .`builtin`. `utf8_lcase`",
+ None,
+ Some(string("UTF8_LCASE")),
+ ),
// JSON reads a name of letters, digits and underscores, as PySpark's
`\w+` does, and a
// letter of any script is one. DDL's unquoted identifiers are of
ASCII letters, digits and
- // underscores only, as Spark's lexer reads them.
+ // underscores only, as Spark's lexer reads them, and its case is
ASCII: the Kelvin sign
+ // (U+212A), which a Unicode lowercase makes a `k`, is not one.
("string collate été", Some(string("été")), None),
+ ("string collate \u{212A}o", Some(string("\u{212A}o")), None),
// JSON is in lower case and of single spaces; the keywords of DDL are
of any case and
// any whitespace.
("DECIMAL(10,2)", None, Some(decimal(10, 2))),
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]