mihaibudiu commented on code in PR #5073:
URL: https://github.com/apache/calcite/pull/5073#discussion_r3538942754
##########
core/src/main/codegen/templates/Parser.jj:
##########
@@ -8470,6 +8470,18 @@ SqlBinaryOperator BinaryRowOperator() :
// <IN> is handled as a special case
<EQ> { return SqlStdOperatorTable.EQUALS; }
| <LEFTSHIFT> { return SqlStdOperatorTable.BIT_LEFT_SHIFT; }
+ // The right shift operator ">>" is matched as two ">" tokens rather than a
+ // single ">>" token. A greedy ">>" token would be produced by the lexer
even
+ // when the two ">" characters close nested angle-bracket types (e.g.
+ // MAP<INT, MAP<INT, INT>>), breaking type parsing. Matching two ">"
tokens here
+ // keeps right shift confined to expression context. The semantic lookahead
+ // requires the two ">" to be immediately adjacent (no intervening
whitespace),
+ // so "a > > b" is not treated as a right shift; otherwise we fall through
to
+ // the single ">" (greater-than) alternative below.
+| LOOKAHEAD({ getToken(1).kind == GT && getToken(2).kind == GT
+ && getToken(1).endLine == getToken(2).beginLine
Review Comment:
Can we make this a helper function in SqlParserPos, maybe called "adjacent"?
##########
core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java:
##########
@@ -920,6 +922,17 @@ void populate1() {
// (e.g., x << y)
defineMethod(BIT_LEFT_SHIFT, BuiltInMethod.LEFT_SHIFT.method,
NullPolicy.STRICT);
+ // Right shift operations: shift bits to the right by specified amount.
+ // Supports integer, unsigned integer, and binary data types.
+ // Shift amount is normalized using modulo arithmetic based on data type
bit width.
+
+ // RIGHTSHIFT: Function call syntax for bitwise right shift operation
(e.g., RIGHTSHIFT(x, y))
+ defineMethod(RIGHTSHIFT, BuiltInMethod.RIGHT_SHIFT.method,
NullPolicy.STRICT);
Review Comment:
Since LEFTSHIFT supports negative amounts, isn't RIGHTSHIFT(a, b) the same
as LEFTSHIFT(a, -b)?
--
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]