[ 
https://issues.apache.org/jira/browse/CALCITE-6700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17902391#comment-17902391
 ] 

Mihai Budiu commented on CALCITE-6700:
--------------------------------------

This kind of case occurs frequently in Calcite. For example, in the reference 
for dialect-specific operators 
https://calcite.apache.org/docs/reference.html#dialect-specific-operators you 
can find 4 different versions of function concat_ws. So the solution is to 
treat bit_count as two different operators, depending on the library loaded.

> MySQL BIT_COUNT function should return result when parameter is Boolean, 
> String types
> -------------------------------------------------------------------------------------
>
>                 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
>            Priority: Major
>              Labels: pull-request-available
>
> 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)

Reply via email to