Skip to content

fix: unparse NULL list, struct, map and union literals as NULL - #26722

Closed
fixfon wants to merge 1 commit into
apache:mainfrom
fixfon:fix/26316-unparser-null-scalar
Closed

fixfon wants to merge 1 commit into
apache:mainfrom
fixfon:fix/26316-unparser-null-scalar

Conversation

@fixfon

@fixfon fixfon commented Oct 24, 2026

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

The unparser turns a NULL list literal into [], so the SQL it writes is a different value from the plan (a NULL FixedSizeList came out as [NULL, NULL]). A NULL struct, map or union literal fails with NotImplemented("Unsupported scalar"), so a plan that contains one can't be unparsed at all.

What changes are included in this PR?

scalar_to_sql now catches a NULL list, struct, map or union first and writes NULL, the same bare NULL the other typed nulls already use. Non-null values are handled as before, so a non-null struct, map or union still returns NotImplemented.

What is the testing strategy for this PR?

Two unit tests in unparser/expr.rs, through expr_to_sql (sqllogictest can't reach the unparser). One checks that a NULL of each of the eight types gives NULL, and that a list holding a NULL list gives [NULL, [1]]. The other checks that an empty list is still [] and a non-null struct still returns NotImplemented. The first test fails on main with eight wrong results and passes with the change. cargo test -p datafusion-sql passes.

Not covered: a union whose active value is NULL, a NULL list wrapped in a dictionary, and non-default dialects. The bare NULL has no type, so a target engine may infer a different one.

Are there any user-facing changes?

Unparsed SQL now has NULL where it used to have [], or an error. No API changes.

AI assistance: Claude (via T3 Code) helped write the change and the test.

The list arms of scalar_to_sql only looked at the child values, so a NULL list was unparsed as an empty array (or an array of NULLs for a fixed-size list), and the struct, map and union arms rejected every value, including NULL. NULLs of these types are now caught first and unparsed as NULL, like the other typed nulls. Non-null struct, map and union literals still return the same NotImplemented error.

Closes apache#26316
@github-actions github-actions Bot added the sql SQL Planner label Oct 24, 2026
@alamb alamb added the Prolific Author author opened PRs or issues in more than 20 repositories in the last 30 days label Oct 27, 2026
@alamb

alamb commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution! I am closing this under DataFusion's AI Dump policy.

https://datafusion.apache.org/contributor-guide/ai-policy.html#what-is-an-ai-dump-and-why-it-is-not-helpful

Review capacity is very limited and this is a PR from a new contributor flagged for opening multiple PRs in a short time, with no engagement since it was opened. The policy asks new contributors to work with maintainers on one PR at a time rather than opening several at once.

If this fix matters to you, please pick the single change you care most about, reopen or resubmit it with a short description in your own words, and we are happy to help with review.

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

Labels

Prolific Author author opened PRs or issues in more than 20 repositories in the last 30 days sql SQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unparser turns NULL list literals into [] and fails on NULL struct/map literals

2 participants