[CALCITE-7547] BIG_QUERY should allow field access on UNNEST of struct array AS alias#4963
Open
takaaki7 wants to merge 1 commit into
Open
[CALCITE-7547] BIG_QUERY should allow field access on UNNEST of struct array AS alias#4963takaaki7 wants to merge 1 commit into
takaaki7 wants to merge 1 commit into
Conversation
…EST(array_of_struct) AS alias Under SqlConformanceEnum.BIG_QUERY, SELECT i.name FROM t, UNNEST(t.items) AS i where items is ARRAY<ROW<name ...>> failed validation with "Column 'NAME' not found in table 'I'" because allowAliasUnnestItems() returned false. With the flag off, SqlUnnestOperator#inferReturnType flattens the ROW element type into individual columns instead of keeping it as a single struct-typed column the alias can wrap, and AliasNamespace cannot remap the flattened result back under the alias. BigQuery itself supports this access pattern, so extend the existing PRESTO case in SqlConformanceEnum#allowAliasUnnestItems() to also cover BIG_QUERY. This complements CALCITE-7546, which removes the downstream NPE in SqlToRelConverter#convertUnnest for the 2-operand AS(UNNEST, alias) form when the flag is enabled.
|
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.



Jira Link
CALCITE-7547
Changes Proposed
Under
SqlConformanceEnum.BIG_QUERY, the following query failed validation withColumn 'NAME' not found in table 'I', even though BigQuery itself supports the pattern:Root cause:
SqlConformanceEnum.BIG_QUERY.allowAliasUnnestItems()returnedfalse. With the flag off,SqlUnnestOperator#inferReturnTypeflattens theROWelement type into one column per field instead of producing a single struct-typed column the alias can wrap, andAliasNamespacecannot remap the flattened result back under the alias. The identical query already validates underSqlConformanceEnum.PRESTO. The flag was added in CALCITE-3789 for Presto and was never extended to BigQuery.Extend the existing PRESTO case in
SqlConformanceEnum#allowAliasUnnestItems()to also coverBIG_QUERY, matching BigQuery's actual semantics. No other conformance is affected.Test plan
SqlValidatorTest#testAliasUnnestMultipleArraysBigQuery— new, mirrors the existing PRESTO test under BIG_QUERY conformance (positive struct-field access, multi-array unnest, two negative cases).SqlToRelConverterTest#testAliasUnnestArrayPlanWithSingleColumnBigQueryandtestAliasUnnestArrayPlanWithDoubleColumnBigQuery— new, with matching XML plan blocks. Plans are identical to the PRESTO equivalents becauseallowAliasUnnestItems()is the only relevant dial.testAliasUnnestMultipleArrays,testAliasUnnestArrayPlanWithSingleColumn,testAliasUnnestArrayPlanWithDoubleColumn.SqlValidatorTest(562) andSqlToRelConverterTest(663) suites pass.