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

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.

…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.
@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.

1 participant