[ 
https://issues.apache.org/jira/browse/CALCITE-6700?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Zhengqiang Duan updated CALCITE-6700:
-------------------------------------
    Description: 
In 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 
date, time and timestamp types.

So, I think we should add a bitCount4MySQL implementation in SqlFunctions to 
adapt to different data types.

  was:
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.


> MySQL BIT_COUNT function should return result when parameter is Boolean, 
> String, Date, Time and Timestamp 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, 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 date, time and timestamp 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