Dwrite opened a new pull request, #4916:
URL: https://github.com/apache/calcite/pull/4916

   Jira Link
   
[CALCITE-7475](https://www.google.com/search?q=https://issues.apache.org/jira/browse/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 <LBRACKET> (for ITEM access) and <DOT> (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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to