feat(isthmus): map RIGHTSHIFT to Substrait shift_right#986
Draft
nielspardon wants to merge 1 commit into
Draft
Conversation
Calcite defines the << operator (BIT_LEFT_SHIFT) and the LEFTSHIFT function, both mapped to Substrait shift_left, but has no right-shift counterpart. Define an Isthmus RIGHTSHIFT(value, shift) SqlFunction mirroring Calcite's LEFTSHIFT, register it in SubstraitOperatorTable so it validates, and map it to the Substrait shift_right function. This covers the function-call spelling RIGHTSHIFT(x, n). The >> infix operator is intentionally out of scope here: Calcite has no >> token, so supporting it requires generating a custom parser.
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.
What
Adds a mapping so a right-shift can be converted to the Substrait
shift_rightfunction. Calcite defines the<<operator (BIT_LEFT_SHIFT) and theLEFTSHIFTfunction — both already mapped to Substraitshift_left— but has no right-shift counterpart at all. This PR defines an IsthmusRIGHTSHIFT(value, shift)SqlFunction(mirroring Calcite'sLEFTSHIFT), registers it inSubstraitOperatorTable, and maps it toshift_right.Why
shift_rightexists infunctions_arithmetic.yaml(i32/i64, same shape asshift_left) but was unreachable from SQL because no Calcite operator produced it.Scope
RIGHTSHIFT(x, n). Round-trips to Substraitshift_rightand back.>>infix operator is intentionally out of scope. Calcite 1.42 has no>>token, noSqlKind, and no operator (only<<). Supporting>>requires isthmus to generate its own parser: Calcite exposes the needed extension hooks (binaryOperatorsTokens+extraBinaryExpressions, the same mechanism calcite-babel uses for the::infix cast), but isthmus currently consumes the prebuiltSqlDdlParserImpland has no parser codegen. Tracking that as a separate follow-up; the cleanest long-term fix is likely to upstreamBIT_RIGHT_SHIFTinto Calcite core (a genuine gap, given it already has<<), after which this reduces to a one-line mapping.Testing
ArithmeticFunctionTest(i8/i16/i32/i64), symmetric to the existingleftshifttest.:isthmus:testsuite passes locally.🤖 Generated with AI