Skip to content

[CALCITE-7566] Support BigQuery-style bare bracket array literals#4975

Draft
takaaki7 wants to merge 1 commit into
apache:mainfrom
takaaki7:dev-0531-144845
Draft

[CALCITE-7566] Support BigQuery-style bare bracket array literals#4975
takaaki7 wants to merge 1 commit into
apache:mainfrom
takaaki7:dev-0531-144845

Conversation

@takaaki7

Copy link
Copy Markdown
Contributor

Summary

  • Adds support for BigQuery-style array literals written without the ARRAY keyword, e.g. SELECT [1, 2, 3], when conformance is BIG_QUERY (also BABEL, LENIENT).
  • Introduces SqlConformance#allowBareBracketArrayLiteral() and gates a new alternative in the JavaCC ArrayConstructor production with it. The new alternative emits the same ARRAY_VALUE_CONSTRUCTOR call used by ARRAY[...], so validation, type derivation, and unparse paths require no other changes.
  • Fixes CALCITE-7566.

Test plan

  • New SqlParserTest#testBareBracketArrayLiteral covers [1, 2, 3], empty [], nested [[1, 2], [3, 4]], subscript [10, 20, 30][1], and SELECT [1, 2, 3] under BIG_QUERY; also asserts BABEL/LENIENT accept and DEFAULT/STRICT_2003 reject.
  • ./gradlew :core:test --tests CoreSqlParserTest --tests SqlUnParserTest — 991 passed, 0 failed (9 pre-existing skips).
  • JavaCC reports no new choice conflicts (the two pre-existing warnings near lines 1975 and 3703 are unchanged).

🤖 Generated with Claude Code

BigQuery accepts array literals written without the ARRAY keyword,
e.g. SELECT [1, 2, 3]. Calcite's parser previously rejected this form
with `Encountered "[" at line 1, column 8` even under
SqlConformanceEnum.BIG_QUERY.

Introduce SqlConformance#allowBareBracketArrayLiteral() (true for
BIG_QUERY, BABEL, LENIENT) and add a conformance-gated alternative in
the JavaCC ArrayConstructor production that consumes `[ ... ]` and
emits the same ARRAY_VALUE_CONSTRUCTOR call used by the existing
`ARRAY[...]` syntax, so validation, type derivation, and unparse paths
need no further change.
@sonarqubecloud

Copy link
Copy Markdown

<LBRACKET> // TODO: do trigraph as well ??( ??)
// BigQuery bare bracket array literal "[e0, e1, ..., eN]"
LOOKAHEAD({ this.conformance.allowBareBracketArrayLiteral() })
<LBRACKET> { s = span(); }

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.

you can handle the empty argument list similar to the spark array constructor, and then the validator won't reject [] anymore. That is rather ugly, it's true, maybe we should fix the validator instead.

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@calcite.apache.org list. Thank you for your contributions.

@github-actions github-actions Bot added the stale label Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants