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


##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -15523,6 +15523,58 @@ void checkBitAnd(SqlOperatorFixture f0, FunctionAlias 
functionAlias) {
     f0.forEachLibrary(list(functionAlias.libraries), consumer);
   }
 
+  @Test public void testBitCountFunc() {
+    final SqlOperatorFixture f = fixture();
+    f.setFor(SqlStdOperatorTable.BITCOUNT, VmName.EXPAND);
+    f.checkFails("bitcount(^*^)", "Unknown identifier '\\*'", false);
+    f.checkType("bitcount(1)", "BIGINT NOT NULL");
+    f.checkType("bitcount(CAST(2 AS TINYINT))", "BIGINT NOT NULL");
+    f.checkType("bitcount(CAST(2 AS SMALLINT))", "BIGINT NOT NULL");
+    f.checkType("bitcount(CAST(x'ad' AS BINARY(1)))", "BIGINT NOT NULL");
+    f.checkFails("^bitcount(1.2)^",
+        "Cannot apply 'BITCOUNT' to arguments of type 
'BITCOUNT\\(<DECIMAL\\(2, 1\\)>\\)'\\. Supported form\\(s\\): 
'BITCOUNT\\(<INTEGER>\\)'\n"
+            + "'BITCOUNT\\(<BINARY>\\)'",
+        false);
+    f.checkFails(
+        "^bitcount()^",
+        "Invalid number of arguments to function 'BITCOUNT'. Was expecting 1 
arguments",
+        false);
+    f.checkFails(
+        "^bitcount(1, 2)^",
+        "Invalid number of arguments to function 'BITCOUNT'. Was expecting 1 
arguments",
+        false);
+    f.checkScalar("bitcount(8)", "1", "BIGINT NOT NULL");
+    f.checkScalar("bitcount(CAST(x'ad' AS BINARY(1)))", "5", "BIGINT NOT 
NULL");
+    f.checkNull("bitcount(cast(NULL as TINYINT))");
+    f.checkNull("bitcount(cast(NULL as BINARY))");
+  }
+
+  @Test public void testBitCountMySQLFunc() {

Review Comment:
   The input number is converted to a 64-bit integer using two's complement. It 
will count the bits set in this, so `bitcount(-1)` will return `64`.
   
   Added a test.



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