normanj-bitquill commented on code in PR #3927:
URL: https://github.com/apache/calcite/pull/3927#discussion_r1729550440


##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -2834,6 +2834,28 @@ public static ByteString bitAnd(ByteString b0, 
ByteString b1) {
     return binaryOperator(b0, b1, (x, y) -> (byte) (x & y));
   }
 
+  /** Helper function for implementing <code>BITCOUNT</code>. Counts the number
+   * of bits set in an integer value. */
+  public static long bitCount(long b) {
+    return Long.bitCount(b);
+  }
+
+  /** Helper function for implementing <code>BITCOUNT</code>. Counts the number
+   * of bits set in the integer portion of a decimal value. */
+  public static long bitCount(BigDecimal b) {
+    return Long.bitCount(b.longValue());

Review Comment:
   I did some more testing with MySQL.
   * bitcount(18446744073709551615) = 64
   * bitcount(18446744073709551616 or greater) = 63
   * bitcount(-9223372036854775808 or less) = 1
   
   I have updating the implementation of `bitcount(BigDecimal)` to match this 
behaviour. This is only enabled in the MySQL library.
   
   It should match MySQL behaviour at the moment, but since this is not really 
documented
   https://dev.mysql.com/doc/refman/8.4/en/bit-functions.html#function_bit-count
   perhaps this is not worth keeping and could change at any time.
   
   In general is it better to match MySQL behaviour (for a MySQL specific 
function) or is it better to take the simpler approach?



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