mihaibudiu commented on code in PR #5073:
URL: https://github.com/apache/calcite/pull/5073#discussion_r3521289321
##########
core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java:
##########
@@ -1396,6 +1396,35 @@ public class SqlStdOperatorTable extends
ReflectiveSqlOperatorTable {
OperandTypes.family(SqlTypeFamily.BINARY, SqlTypeFamily.INTEGER),
OperandTypes.family(SqlTypeFamily.UNSIGNED_NUMERIC,
SqlTypeFamily.INTEGER)));
+ /**
+ * <code>{@code >>}</code> (right shift) operator.
+ */
+ public static final SqlBinaryOperator BIT_RIGHT_SHIFT =
+ new SqlBinaryOperator(
+ ">>",
+ SqlKind.OTHER,
+ 32, // Standard shift operator
precedence
+ true,
+ ReturnTypes.ARG0_NULLABLE,
+ InferTypes.FIRST_KNOWN,
+ OperandTypes.or(
+ OperandTypes.family(SqlTypeFamily.INTEGER,
SqlTypeFamily.INTEGER),
+ OperandTypes.family(SqlTypeFamily.BINARY, SqlTypeFamily.INTEGER),
+ OperandTypes.family(SqlTypeFamily.UNSIGNED_NUMERIC,
SqlTypeFamily.INTEGER)));
+
+ /**
+ * right shift function.
+ */
+ public static final SqlFunction RIGHTSHIFT =
+ SqlBasicFunction.create(
+ "RIGHTSHIFT",
+ SqlKind.OTHER_FUNCTION,
+ ReturnTypes.ARG0_NULLABLE,
+ OperandTypes.or(
Review Comment:
This could be factored in a single definition. Maybe it's used in other
places too.
##########
core/src/main/codegen/templates/Parser.jj:
##########
@@ -8470,6 +8470,12 @@ 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 adjacent ">" 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.
+| LOOKAHEAD(2) <GT> <GT> { return SqlStdOperatorTable.BIT_RIGHT_SHIFT; }
Review Comment:
I think this will match even with a space between the `>` characters. You
need to really check that they are next to each other, using SqlParserPos.
--
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]