[CALCITE-7639] Support bitwise right shift (>>) operator and RIGHTSHIFT function#5073
Open
nielspardon wants to merge 1 commit into
Open
[CALCITE-7639] Support bitwise right shift (>>) operator and RIGHTSHIFT function#5073nielspardon wants to merge 1 commit into
nielspardon wants to merge 1 commit into
Conversation
bb53cb6 to
a6d5390
Compare
…FT function
Mirrors the left-shift work in CALCITE-7109 to close a gap in the umbrella
issue CALCITE-5087. Adds:
* `>>` (SqlStdOperatorTable.BIT_RIGHT_SHIFT), a signed/arithmetic right
shift (Java `>>`), symmetric to `<<` (precedence 32, left-assoc,
ReturnTypes.ARG0_NULLABLE, InferTypes.FIRST_KNOWN, and the same
INTEGER / BINARY / UNSIGNED_NUMERIC operand families).
* `RIGHTSHIFT(x, n)` scalar function, mirroring `LEFTSHIFT`.
* SqlFunctions.rightShift(...) runtime overloads (int, long, byte[],
ByteString, and the joou unsigned types), plus BuiltInMethod.RIGHT_SHIFT
and the RexImpTable registrations for both operator and function.
Unlike `<<`, a greedy `>>` token cannot be added: the lexer would also match
the two `>` that close nested angle-bracket types (e.g. MAP<INT, MAP<INT,
INT>>), breaking type parsing. `>>` is therefore recognized in expression
context as two adjacent `>` tokens via LOOKAHEAD(2) in BinaryRowOperator,
leaving type parsing unchanged. Because there is no dedicated token, the SQL
advisor advertises `>` rather than `>>`, so SqlAdvisorTest is not modified.
Scope is limited to `>>` (arithmetic). The logical/fill-zero `>>>`
(RIGHT_SHIFT_FILL_ZERO) remains a possible follow-up.
Tests: SqlOperatorTest (operator + function forms), SqlFunctionsTest,
operator.iq, and the operator-precedence dump in SqlValidatorTest; docs in
site/_docs/reference.md.
a6d5390 to
d765854
Compare
|
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-7109
Changes Proposed
Mirrors the left-shift work in CALCITE-7109 to close a gap in the umbrella issue CALCITE-5087.
Adds:
>>(SqlStdOperatorTable.BIT_RIGHT_SHIFT), a signed/arithmetic right shift (Java>>), symmetric to<<(precedence 32, left-assoc, ReturnTypes.ARG0_NULLABLE, InferTypes.FIRST_KNOWN, and the same INTEGER / BINARY / UNSIGNED_NUMERIC operand families).RIGHTSHIFT(x, n)scalar function, mirroringLEFTSHIFT.Unlike
<<, a greedy>>token cannot be added: the lexer would also match the two>that close nested angle-bracket types (e.g. MAP<INT, MAP<INT, INT>>), breaking type parsing.>>is therefore recognized in expression context as two adjacent>tokens via LOOKAHEAD(2) in BinaryRowOperator, leaving type parsing unchanged. Because there is no dedicated token, the SQL advisor advertises>rather than>>, so SqlAdvisorTest is not modified.Scope is limited to
>>(arithmetic). The logical/fill-zero>>>(RIGHT_SHIFT_FILL_ZERO) remains a possible follow-up.The code in this PR was generated with the help of AI.