Skip to content

[CALCITE-7448] Add support for : as a field/item access operator#4844

Open
tmater wants to merge 7 commits intoapache:mainfrom
tmater:colon-syntax-mode
Open

[CALCITE-7448] Add support for : as a field/item access operator#4844
tmater wants to merge 7 commits intoapache:mainfrom
tmater:colon-syntax-mode

Conversation

@tmater
Copy link

@tmater tmater commented Mar 24, 2026

Changes Proposed

This PR adds opt-in support for : as a field/item access operator behind a new SqlConformance#isColonFieldAccessAllowed() hook. No built-in conformance enables it yet, so the default parser behavior is unchanged.

It also refactors postfix parsing so colon field access composes with existing dot and bracket access. That covers cases such as v:field, v:['field name'], arr[1]:field, obj['x']:nested['y'], and colon access followed by bracket or dot postfixes.

To avoid ambiguity when colon field access is enabled, JSON_OBJECT and JSON_OBJECTAGG must use VALUE syntax instead of : or comma-separated key/value shorthand.

The Babel parser coverage is updated as well so PostgreSQL-style infix casts still require parentheses before bracket access. For example, (v::variant)[1] parses as item access on the cast result, while v::variant[1] remains invalid.

Reproduction

select v:field, v:['field name'], arr[1]:field, obj['x']:nested from t;

select json_object(key v:field value arr[1]:field);

select (v::variant)[1] from t;

Testing

Added parser coverage in SqlParserTest and BabelParserTest for valid and invalid colon field access, JSON constructor disambiguation, and :: cast interactions.

Jira Link

CALCITE-7448

@caicancai
Copy link
Member

I might wait until the CI issue is resolved before reviewing this PR.

@sonarqubecloud
Copy link

@caicancai
Copy link
Member

I don't understand Calcite JavaCC code very well, I might need to learn it. If no one reviews it this week, I'll start working on it next week.

@tmater
Copy link
Author

tmater commented Mar 25, 2026

I don't understand Calcite JavaCC code very well, I might need to learn it. If no one reviews it this week, I'll start working on it next week.

Thank you for taking a look, @caicancai. I agree this is still a fairly complex PR, and I wouldn’t claim to fully understand all of its implications yet.

That’s also why I tried to include a wide range of test variations and keep the changes gated behind a conformance config.

I’ve organized it into five commits (prior to the CI failures) to make the review easier. If it would help further, I’m happy to split it into 4–5 smaller PRs.

@mihaibudiu
Copy link
Contributor

Is the behavior with :: needing parenthesis a new feature, or was this already present previously?

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