[ 
https://issues.apache.org/jira/browse/CALCITE-7639?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18093997#comment-18093997
 ] 

Niels Pardon commented on CALCITE-7639:
---------------------------------------

The idea of this proposal is to mirror what was proposed in 
https://issues.apache.org/jira/browse/CALCITE-7109 for left shift but for right 
shift to create symmetry with the already implemented LEFTSHIFT since I have a 
use case where I needed RIGHTSHIFT. Currently, no concrete plans yet on any 
further work in that area. The operator proposed here would be sign-extending 
just like the existing LEFTSHIFT is.



*Sign extension behaviour:*
>> is implemented as an arithmetic (sign-extending) right shift for signed 
>> integer types — it maps directly to Java's >> operator. So for a signed 
>> integer, the sign bit is propagated into the vacated high-order bits. 
>> Examples:
 * 8 >> 2 → 2 (positive, zeros fill in)
 * -20 >> 2 → -5 (negative, ones fill in — sign is preserved)

For unsigned types (TINYINT UNSIGNED, SMALLINT UNSIGNED, INTEGER UNSIGNED, 
BIGINT UNSIGNED) it is a logical (zero-filling) shift, since there is no sign 
bit to extend — vacated bits are always filled with zeros.

For binary/VARBINARY types it is also a logical right shift (zero-filling), 
consistent with how PostgreSQL treats bytea shifts.

> Support bitwise right shift (>>) operator and RIGHTSHIFT function
> -----------------------------------------------------------------
>
>                 Key: CALCITE-7639
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7639
>             Project: Calcite
>          Issue Type: New Feature
>          Components: core
>    Affects Versions: 1.42.0
>            Reporter: Niels Pardon
>            Assignee: Niels Pardon
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.43.0
>
>
> CALCITE-7109 added support for bitwise left shift operator << and the 
> LEFTSHIFT function.
> This issue covers adding the bitwise right shift operator >> and the 
> RIGHTSHIFT function along the same lines.
> The operator proposed here 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to