Skip to content

[CALCITE-7546] NullPointerException in SqlToRelConverter for UNNEST(array) AS alias under conformance with allowAliasUnnestItems=true#4962

Open
takaaki7 wants to merge 1 commit into
apache:mainfrom
takaaki7:CALCITE-7546
Open

[CALCITE-7546] NullPointerException in SqlToRelConverter for UNNEST(array) AS alias under conformance with allowAliasUnnestItems=true#4962
takaaki7 wants to merge 1 commit into
apache:mainfrom
takaaki7:CALCITE-7546

Conversation

@takaaki7

Copy link
Copy Markdown
Contributor

Summary

  • Fixes CALCITE-7546: SqlToRelConverter throws NullPointerException: fieldNames for UNNEST(<array>) AS <alias> (no column list) under a conformance whose allowAliasUnnestItems() returns true (SqlConformanceEnum.PRESTO, plus user conformances overriding the flag).
  • convertFrom's AS branch 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 (e.g. UNNEST(d.employees) AS ee.empno) and scalar element types (e.g. UNNEST(d.admins) AS aa) resolve correctly.

Test plan

  • Added testAliasUnnestArrayPlanWithoutColumnList (struct array, PRESTO) — reproduces the NPE on main, passes after the fix.
  • Added testAliasUnnestScalarArrayPlanWithoutColumnList (scalar varchar array, PRESTO).
  • Existing PRESTO/UNNEST regression tests still pass: testAliasUnnestArrayPlanWithSingleColumn, testAliasUnnestArrayPlanWithDoubleColumn, testUnnestArrayPlan, testUnnestArrayPlanAs.
  • Full SqlToRelConverterTest (663) and RelToSqlConverterTest (579) suites pass.

* NullPointerException in SqlToRelConverter for UNNEST(array) AS alias under
* conformance with allowAliasUnnestItems=true</a>.
*/
@Test void testAliasUnnestArrayPlanWithoutColumnList() {

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.

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.

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.

Thanks, I've added the test.

@sonarqubecloud

Copy link
Copy Markdown

@mihaibudiu

Copy link
Copy Markdown
Contributor

Please squash the commits so we can merge this

@mihaibudiu

Copy link
Copy Markdown
Contributor

We may need to wait for the 1.43 release to merge this

@mihaibudiu

Copy link
Copy Markdown
Contributor

@takaaki7 let's finalize this: can you please fix the conflicts and squash the commits?

@takaaki7 takaaki7 force-pushed the CALCITE-7546 branch 3 times, most recently from c772788 to 93e7ff6 Compare June 25, 2026 06:39
…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.

Add tests for struct array, scalar array, and the exact array literal
reproduction from the issue ("SELECT t FROM UNNEST(ARRAY[1, 2, 3]) AS t").
@takaaki7

Copy link
Copy Markdown
Contributor Author

Squashed.

@sonarqubecloud

Copy link
Copy Markdown

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.

3 participants