Zhengqiang Duan created CALCITE-6700:
----------------------------------------
Summary: BIT_COUNT function validate error when execute BIT_COUNT
query with different mysql type
Key: CALCITE-6700
URL: https://issues.apache.org/jira/browse/CALCITE-6700
Project: Calcite
Issue Type: Bug
Affects Versions: 1.38.0
Reporter: Zhengqiang Duan
Assignee: Zhengqiang Duan
In [CALCITE-3697|https://issues.apache.org/jira/browse/CALCITE-3697], Caclite
already supports MySQL BIT_COUNT by reusing the standard BITCOUNT function
logic, but when I tested more MySQL data types, the Calcite validator would
report errors because the standard BITCOUNT function does not support these
types.
For example, when I execute the following query, the Calcite validator throws
the exception Cannot apply 'BIT_COUNT' to arguments of type
'BIT_COUNT(<BOOLEAN>)'. Supported form(s): 'BIT_COUNT(<NUMERIC>)'.
{code:java}
SELECT bit_count(123456), bit_count('123456'), bit_count('abcdefg'),
BIT_COUNT('abcdef1234'), bit_count(''), bit_count(1 + 1), bit_count(true) {code}
Executed via MySQL, they all return correct results.
{code:java}
mysql> SELECT bit_count(123456), bit_count('123456'), bit_count('abcdefg'),
BIT_COUNT('abcdef1234'), bit_count(''), bit_count(1 + 1), bit_count(true) ;
+-------------------+---------------------+----------------------+-------------------------+---------------+------------------+-----------------+
| bit_count(123456) | bit_count('123456') | bit_count('abcdefg') |
BIT_COUNT('abcdef1234') | bit_count('') | bit_count(1 + 1) | bit_count(true) |
+-------------------+---------------------+----------------------+-------------------------+---------------+------------------+-----------------+
| 6 | 6 | 0 |
0 | 0 | 1 | 1 |
+-------------------+---------------------+----------------------+-------------------------+---------------+------------------+-----------------+
1 row in set, 3 warnings (0.00 sec) {code}
In addition to the sample SQL above, the MySQL BIT_COUNT function also supports
time, datetime, timestamp, year and other types.
So, I think we should add a bitCount4MySQL implementation in SqlFunctions to
adapt to different data types.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)