Dwrite commented on code in PR #4478: URL: https://github.com/apache/calcite/pull/4478#discussion_r2328699105
########## core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java: ########## @@ -3506,6 +3506,152 @@ private static ByteString binaryOperator( return new ByteString(result); } + /** + * Performs bitwise shift on two integers. + * If the shift amount is positive, a left shift is applied. + * If the shift amount is negative, a logical right shift is applied. + * The shift amount is taken modulo 32. + */ + + public static int leftShift(int x, int y) { + int shift = Math.abs(y % 32); + return y >= 0 ? x << shift : x >>> shift; + } + + /** + * Performs bitwise shift on a long value. + * If the shift amount is positive, a left shift is applied. + * If the shift amount is negative, a logical right shift is applied. + * The shift amount is taken modulo 64. + */ + + public static long leftShift(long x, int y) { + int shift = Math.abs(y % 64); + return y >= 0 ? x << shift : x >>> shift; + } + + /** + * Performs bitwise shift with long shift amount. + * Note: input x is int, so shift mod 32 is used. + * Returns long to prevent overflow. + */ + public static long leftShift(int x, long y) { + int shift = (int) Math.abs(y % 32); + return y >= 0 ? (long) x << shift : (long) x >>> shift; + } + + /** + * Performs bitwise shift on a byte array. + * A positive shift amount performs a left shift. + * A negative shift amount performs a logical right shift. + */ + public static ByteString leftShift(ByteString bytes, int y) { + byte[] result = leftShift(bytes.getBytes(), y); + return new ByteString(result); + } + + /** + * Performs bitwise shift on a byte array. + * A positive shift amount performs a left shift. + * A negative shift amount performs a logical right shift. + */ + public static byte[] leftShift(byte[] bytes, int y) { Review Comment: Thanks for clarifying earlier. I’ve added a dedicated unit test for SqlFunctions.leftShift and placed it in SqlFunctionsTest.java, following the existing Calcite test style. Could you confirm if this is the location and style you had in mind? -- 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: commits-unsubscr...@calcite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org