Repository navigation
fix(duckdb): type one-argument unnest as a nullable element - #4725
Open
tonycoder-hub wants to merge 1 commit into
Open
tonycoder-hub wants to merge 1 commit into
tonycoder-hub wants to merge 1 commit into
Conversation
Seed DuckDB unnest(anyarray) -> anyelement, nullable because a list element can be NULL, following Spanner's unnest. FROM unnest and a select-list unnest(nums) over INTEGER[] are then the element type (sql.NullInt32), not unknown and not any. Calls with more arguments, including recursive and max_depth, stay untyped. Fixes sqlc-dev#4712 Signed-off-by: Tony Coder <407243179@qq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4712
DuckDB accepts unnest as a table function, but sqlc reported unknown function "unnest" because the dialect seed never included it.
Seed the one-argument form the way PostgreSQL does, unnest(anyarray) -> anyelement, and mark it nullable the way Spanner's unnest is: a list element can be NULL. FROM unnest(items) AS u(it) is the struct element. A select-list unnest(nums) over INTEGER[] is sql.NullInt32, not int32 and not any.
Other arities, unnest(list, recursive := true) and unnest(list, max_depth := n), are deliberately left untyped, because DuckDB expands them into several columns (#4713, out of scope). The two small guards in expr.go and scope.go that keep them untyped have no test, since the correct output there is #4713's job.
The new analyze_unnest/duckdb case (with a fixture containing NULL elements) fails on main with unknown function "unnest" and passes here; goldeneye's live DuckDB check passes for that case and shows no diff for the unnest seed line. Full TestReplay passes.
Open PR #4719 also types a one-argument select-list unnest (via typeFuncCall). The results agree, but both touch internal/core/analyzer/expr.go, so whichever lands second needs a small rebase. Happy to rebase onto it.