julianhyde commented on code in PR #3927:
URL: https://github.com/apache/calcite/pull/3927#discussion_r1727711813
##########
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() {
+ final SqlOperatorFixture f0 = fixture();
+ f0.setFor(SqlLibraryOperators.BIT_COUNT_MYSQL, VmName.EXPAND);
+ final Consumer<SqlOperatorFixture> consumer = f -> {
+ f.checkFails("bit_count(^*^)", "Unknown identifier '\\*'", false);
+ f.checkType("bit_count(1)", "BIGINT NOT NULL");
+ f.checkType("bit_count(CAST(2 AS TINYINT))", "BIGINT NOT NULL");
+ f.checkType("bit_count(CAST(2 AS SMALLINT))", "BIGINT NOT NULL");
+ f.checkType("bit_count(CAST(2 AS DOUBLE))", "BIGINT NOT NULL");
+ f.checkFails(
+ "^bit_count()^",
+ "Invalid number of arguments to function 'BIT_COUNT'. Was expecting
1 arguments",
+ false);
+ f.checkFails(
+ "^bit_count(1, 2)^",
+ "Invalid number of arguments to function 'BIT_COUNT'. Was expecting
1 arguments",
+ false);
+ f.checkScalar("bit_count(8)", "1", "BIGINT NOT NULL");
+ f.checkScalar("bit_count(CAST(x'ad' AS BINARY(1)))", "5", "BIGINT NOT
NULL");
+ f.checkScalar("bit_count(5.23)", "2", "BIGINT NOT NULL");
Review Comment:
so it ignores bits in the fractional part? that's rather subtle. worth
calling out in the test, and also in the `bitCount(BigDecimal)` function
--
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]