Repository navigation
[common] Preserve NULL values in complex default literals - #11312
zhangyue19921010 wants to merge 5 commits into
Conversation
…61121 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The remaining CI failures are JDK setup errors (tar exit 2). Could you rerun them? |
JingsongLi
left a comment
There was a problem hiding this comment.
The 69 focused Java cases and eight Spark 3.5.9 default-value tests passed. SQL should be able to express these NULL defaults. A separate upgrade replay against a schema created by the old runtime showed a change in the meaning of an existing default.
| // only an unquoted null is the null element; "null" is the four-character string | ||
| Object element = | ||
| !token.literal() && "null".equals(value) | ||
| !token.literal() && "null".equalsIgnoreCase(value) |
There was a problem hiding this comment.
[P1] Preserve the meaning of defaults already stored in table schemas. I used the base runtime to set [NULL] as the ARRAY<STRING> default with SchemaChange.updateColumnDefaultValue and write an omitted column. The stored row contains the four-character string NULL. I opened the same table under this revision and wrote another omitted column without changing the schema. The new row contains a SQL null element, while the old row still contains the string. During a writer rollout, the same persisted default can now produce two values. Please normalize SQL NULL tokens when converting new SQL defaults to metadata, or version the persisted literal grammar so existing schemas keep their meaning. The map and row token changes need the same compatibility check.
There was a problem hiding this comment.
Fixed in 8f7360b: the stored literal grammar is unchanged again (only an unquoted lowercase null token is null, so an existing [NULL] keeps meaning the string for arrays, maps and rows), and Spark instead lowercases nested SQL NULL keywords when converting CREATE and ALTER defaults to metadata.
…SQL NULL in Spark defaults
Purpose
Fixes #11311
Creating a table with defaults such as
ARRAY(1, NULL),MAP(1, NULL)orSTRUCT(1, NULL)fails because the complex cast rules treat uppercase NULL as a value to parse. Whole-value NULL defaults also fail for ARRAY and ROW.Spark CREATE and ALTER defaults now lowercase the SQL
NULLkeyword nested in a complex literal when it is stored, since only an unquoted lowercasenulltoken is null in the stored literal grammar. The grammar itself is unchanged, so a default already stored as[NULL]keeps meaning the four-character string. A whole-valueNULL(any case) is accepted for ARRAY and ROW, which previously failed to parse. Projecting a NULL row default also preserves NULL.Tests
Added Spark SQL create/alter/write/read regressions, cast tests for whole-value NULL in any case, and a cast test that bare, quoted and escaped non-lowercase
NULLtokens stay strings.CastExecutorTest,DefaultValueRowTestand SparkDefaultValueTest(73 tests) pass with Checkstyle and Spotless enabled (JDK 11, Spark 3.5.9). Coverage includes projecting a NULL row default.