nielspardon commented on PR #5073:
URL: https://github.com/apache/calcite/pull/5073#issuecomment-4957022899

   Agreed — design first. I dug into the current behaviour and the precedents:
   
   - Our `byte[]` shift treats the array as **little-endian** and modulo-wraps 
the amount. The "PostgreSQL behavior" comment is misattributed: PostgreSQL 
doesn't define `<<`/`>>` on `bytea` — only on bit strings, which are 
big-endian, length-preserving, zero-filled and don't wrap. MySQL's shifts 
operate on the integer value, not the bytes.
   - CALCITE-7368 made `CAST(int AS BINARY)` big-endian, so today CAST and 
shift disagree. Your identity `CAST(int AS BINARY(N)) << x = CAST((int << x) AS 
BINARY(N))` holds only under big-endian + zero-fill + no-wrap, and even then 
only for `0 ≤ x < 8·N` and matching width (Java's native `int <<` masks the 
amount mod 32, so it diverges at `x ≥ 32`).
   - Binary left shift shipped in 1.41.0/1.42.0, so flipping its endianness is 
a released-behaviour change that deserves its own discussion.
   
   So rather than cement the little-endian semantics in a new operator, I've 
**descoped `BINARY`/`VARBINARY` from `>>` and `RIGHTSHIFT`** in this PR — it 
now covers only the integer/unsigned surface, and a binary operand is rejected 
at validation (pinned by `checkFails`). I filed 
[CALCITE-7651](https://issues.apache.org/jira/browse/CALCITE-7651) to settle 
binary-shift endianness for both `<<` and `>>` together, where I'll propose 
big-endian to match CALCITE-7368 and PostgreSQL bit strings. Binary left shift 
is left exactly as released.
   
   Does that split work for you?
   


-- 
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]

Reply via email to