mihaibudiu commented on code in PR #3927:
URL: https://github.com/apache/calcite/pull/3927#discussion_r1728367399


##########
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:
   Personally I think this behavior is very unexpected, and I think decimals 
should not be supported at all.
   Moreover, this is not the number of 1 bits in the actual internal 
representation, but in the conversion of the decimal to a long.



##########
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:
   This also rounds down the decimal number, which is not obvious.
   Please also note that a decimal may not fit into a long since we merged 
https://github.com/apache/calcite/pull/3589
   So I am not sure this implementation is correct



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