Skip to content

[common] Preserve NULL values in complex default literals - #11312

Open
zhangyue19921010 wants to merge 5 commits into
apache:masterfrom
zhangyue19921010:contrib/preserve-complex-null-literals-20261121
Open

zhangyue19921010 wants to merge 5 commits into
apache:masterfrom
zhangyue19921010:contrib/preserve-complex-null-literals-20261121

Conversation

@zhangyue19921010

@zhangyue19921010 zhangyue19921010 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Fixes #11311

Creating a table with defaults such as ARRAY(1, NULL), MAP(1, NULL) or STRUCT(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 NULL keyword nested in a complex literal when it is stored, since only an unquoted lowercase null token 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-value NULL (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 NULL tokens stay strings.

CastExecutorTest, DefaultValueRowTest and Spark DefaultValueTest (73 tests) pass with Checkstyle and Spotless enabled (JDK 11, Spark 3.5.9). Coverage includes projecting a NULL row default.

@zhangyue19921010

Copy link
Copy Markdown
Contributor Author

The remaining CI failures are JDK setup errors (tar exit 2). Could you rerun them?

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Complex default values reject SQL NULL literals

2 participants