[CALCITE-7546] NullPointerException in SqlToRelConverter for UNNEST(array) AS alias under conformance with allowAliasUnnestItems=true#4962
Open
takaaki7 wants to merge 2 commits into
Open
Conversation
…rray) AS alias under conformance with allowAliasUnnestItems=true Under a SqlConformance where allowAliasUnnestItems() is true (SqlConformanceEnum.PRESTO and user conformances overriding the flag), the AS branch in convertFrom passes fieldNames=null to convertUnnest when the AS clause omits a column list. The PRESTO-only branch then called requireNonNull(fieldNames, "fieldNames") and threw NPE. Fall back to default item aliases derived from SqlUtil#deriveAliasFromOrdinal, matching the names that SqlUnnestOperator#inferReturnType uses during validation. This keeps the relational row type aligned with the validator's underlying namespace so both struct and scalar element types resolve correctly.
4 tasks
mihaibudiu
approved these changes
May 24, 2026
mihaibudiu
reviewed
May 24, 2026
| * NullPointerException in SqlToRelConverter for UNNEST(array) AS alias under | ||
| * conformance with allowAliasUnnestItems=true</a>. | ||
| */ | ||
| @Test void testAliasUnnestArrayPlanWithoutColumnList() { |
Contributor
There was a problem hiding this comment.
Neither of the test cases here matches the one in the issue, but they look close enough.
I hope that you have validated that the test in the issue passes as well.
… reproduction
Add testAliasUnnestArrayLiteralPlanWithoutColumnList using the exact SQL
from the issue ("SELECT t FROM UNNEST(ARRAY[1, 2, 3]) AS t"), which
exercises the same convertUnnest fallback as the column-reference cases
but through a standalone (non-correlated) Uncollect tree. Verified that
the new test reproduces "NullPointerException: fieldNames" against the
pre-fix code and passes with the fix.
|
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.



Summary
SqlToRelConverterthrowsNullPointerException: fieldNamesforUNNEST(<array>) AS <alias>(no column list) under a conformance whoseallowAliasUnnestItems()returns true (SqlConformanceEnum.PRESTO, plus user conformances overriding the flag).convertFrom'sASbranch passesfieldNames=nulltoconvertUnnestwhen the AS clause omits a column list. The PRESTO-only branch then calledrequireNonNull(fieldNames, "fieldNames")and threw NPE.SqlUtil#deriveAliasFromOrdinal, matching the names thatSqlUnnestOperator#inferReturnTypeuses during validation. This keeps the relational row type aligned with the validator's underlying namespace, so both struct (e.g.UNNEST(d.employees) AS e→e.empno) and scalar element types (e.g.UNNEST(d.admins) AS a→a) resolve correctly.Test plan
testAliasUnnestArrayPlanWithoutColumnList(struct array, PRESTO) — reproduces the NPE onmain, passes after the fix.testAliasUnnestScalarArrayPlanWithoutColumnList(scalar varchar array, PRESTO).testAliasUnnestArrayPlanWithSingleColumn,testAliasUnnestArrayPlanWithDoubleColumn,testUnnestArrayPlan,testUnnestArrayPlanAs.SqlToRelConverterTest(663) andRelToSqlConverterTest(579) suites pass.