[CALCITE-7475] Babel parser allows postfix access after PostgreSQL-style :: infix cast#4916
Open
Dwrite wants to merge 3 commits intoapache:mainfrom
Open
[CALCITE-7475] Babel parser allows postfix access after PostgreSQL-style :: infix cast#4916Dwrite wants to merge 3 commits intoapache:mainfrom
Dwrite wants to merge 3 commits intoapache:mainfrom
Conversation
added 3 commits
May 3, 2026 22:08
…yle :: infix cast
…yle :: infix cast
|
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-7475
Changes Proposed
Summary
This PR fixes an issue in the Babel parser where postfix operators (such as array element access [] and field access .) were incorrectly handled or failed when following a PostgreSQL-style infix cast (::).
Problem
Previously, the parser could not clearly distinguish between a subscript that is part of a type definition (e.g., VARCHAR ARRAY) and a subscript that is an operator acting on the result of the cast. For example, in the expression 'test'::VARCHAR ARRAY[1], the [1] was often greedily or incorrectly consumed, leading to parsing errors or an invalid AST.
Solution
Eager Reduction in Parser: Modified the InfixCast logic to eagerly build the SqlCall for the :: operator. This ensures the cast is correctly scoped before handling any subsequent operators.
Postfix Expression Loop: Introduced a loop within the InfixCast rule to explicitly handle trailing (for ITEM access) and (for field access). This prevents these operators from being lost or incorrectly associated with the type specification.
Refined InfixCastDataType: Created a restricted variant of the data type parser specifically for infix casts. It correctly handles the ARRAY keyword while leaving subscript consumption to the expression layer.
Improved Unparsing: Updated the unparse logic for the :: operator to rely on operator precedence rather than forcing redundant parentheses, ensuring cleaner and more idiomatic PostgreSQL-style SQL output.