doris icon indicating copy to clipboard operation
doris copied to clipboard

[fix](DECIMAL) error DECIMAL cat to BOOLEAN

Open Mryange opened this issue 1 year ago • 12 comments

Proposed changes

before

mysql []>select 3.14 and 3.0;
+--------------------------------------------------+
| (cast(3.14 as BOOLEAN) AND cast(3.0 as BOOLEAN)) |
+--------------------------------------------------+
|                                                3 |
+--------------------------------------------------+
mysql [test]>select cast(3.000 as boolean) ;
+------------------------+
| cast(3.000 as BOOLEAN) |
+------------------------+
|                      3 |
+------------------------+

now

mysql [test]>select cast(3.000 as boolean) ;
+------------------------+
| cast(3.000 as BOOLEAN) |
+------------------------+
|                      1 |
+------------------------+

In the past, casting DECIMAL to BOOLEAN directly converted it to an integer.

Further comments

If this is a relatively large or complex change, kick off the discussion at [email protected] by explaining why you chose the solution you did and what alternatives you considered, etc...

Mryange avatar Apr 19 '24 02:04 Mryange

Thank you for your contribution to Apache Doris. Don't know what should be done next? See How to process your PR

Since 2024-03-18, the Document has been moved to doris-website. See Doris Document.

doris-robot avatar Apr 19 '24 02:04 doris-robot

run buildall

Mryange avatar Apr 19 '24 02:04 Mryange

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar Apr 19 '24 02:04 github-actions[bot]

TeamCity be ut coverage result: Function Coverage: 35.44% (8921/25174) Line Coverage: 27.14% (73318/270118) Region Coverage: 26.26% (37861/144178) Branch Coverage: 23.07% (19300/83648) Coverage Report: http://coverage.selectdb-in.cc/coverage/e2f4d188fa0eec6fc6d7f7a3a4c3b178d4fc0977_e2f4d188fa0eec6fc6d7f7a3a4c3b178d4fc0977/report/index.html

doris-robot avatar Apr 19 '24 03:04 doris-robot

https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#function_cast

cast function of mysql do not support using bool as type argument.

zhiqiang-hhhh avatar Apr 19 '24 07:04 zhiqiang-hhhh

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar Apr 19 '24 07:04 github-actions[bot]

https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#function_cast

cast function of mysql do not support using bool as type argument.

But there is implicit conversion to boolean. https://dbfiddle.uk/FGUsvxTk

Mryange avatar Apr 19 '24 07:04 Mryange

run buildall

Mryange avatar Apr 19 '24 07:04 Mryange

https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#function_cast cast function of mysql do not support using bool as type argument.

But there is implicit conversion to boolean. https://dbfiddle.uk/FGUsvxTk

why do you think there is an implicit conversion?

https://dev.mysql.com/doc/refman/8.3/en/logical-operators.html#operator_and

oprator_and checks whether operands are zero or NULL, it has nothing to do with type convert.

zhiqiang-hhhh avatar Apr 19 '24 08:04 zhiqiang-hhhh

https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#function_cast cast function of mysql do not support using bool as type argument.

But there is implicit conversion to boolean. https://dbfiddle.uk/FGUsvxTk

why do you think there is an implicit conversion?

https://dev.mysql.com/doc/refman/8.3/en/logical-operators.html#operator_and

oprator_and checks whether operands are zero or NULL, it has nothing to do with type convert.

My mistake, as doris implementation involves implicit conversion. But such results in doris

mysql []>set enable_fold_constant_by_be = false;
Query OK, 0 rows affected (0.00 sec)

mysql []>select 3.14 and 3.0;
+--------------------------------------------------+
| (cast(3.14 as BOOLEAN) AND cast(3.0 as BOOLEAN)) |
+--------------------------------------------------+
|                                                3 |
+--------------------------------------------------+
1 row in set (0.03 sec)

mysql []>desc select 3.14 and 3.0;
+----------------------------------------------------------+
| Explain String(Nereids Planner)                          |
+----------------------------------------------------------+
| PLAN FRAGMENT 0                                          |
|   OUTPUT EXPRS:                                          |
|     (cast(3.14 as BOOLEAN) AND cast(3.0 as BOOLEAN))[#0] |
|   PARTITION: UNPARTITIONED                               |
|                                                          |
|   HAS_COLO_PLAN_NODE: false                              |
|                                                          |
|   VRESULT SINK                                           |
|      MYSQL_PROTOCAL                                      |
|                                                          |
|   0:VUNION(30)                                           |
|      constant exprs:                                     |
|          CAST(3.14 AS BOOLEAN) AND CAST(3.0 AS BOOLEAN)  |
+----------------------------------------------------------+
13 rows in set (0.01 sec)

mysql []>select 3.14 and 2.0;
+--------------------------------------------------+
| (cast(3.14 as BOOLEAN) AND cast(2.0 as BOOLEAN)) |
+--------------------------------------------------+
|                                                2 |
+--------------------------------------------------+

Mryange avatar Apr 19 '24 08:04 Mryange

https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#function_cast cast function of mysql do not support using bool as type argument.

But there is implicit conversion to boolean. https://dbfiddle.uk/FGUsvxTk

why do you think there is an implicit conversion? https://dev.mysql.com/doc/refman/8.3/en/logical-operators.html#operator_and oprator_and checks whether operands are zero or NULL, it has nothing to do with type convert.

My mistake, as doris implementation involves implicit conversion. But such results in doris

mysql []>set enable_fold_constant_by_be = false;
Query OK, 0 rows affected (0.00 sec)

mysql []>select 3.14 and 3.0;
+--------------------------------------------------+
| (cast(3.14 as BOOLEAN) AND cast(3.0 as BOOLEAN)) |
+--------------------------------------------------+
|                                                3 |
+--------------------------------------------------+
1 row in set (0.03 sec)

mysql []>desc select 3.14 and 3.0;
+----------------------------------------------------------+
| Explain String(Nereids Planner)                          |
+----------------------------------------------------------+
| PLAN FRAGMENT 0                                          |
|   OUTPUT EXPRS:                                          |
|     (cast(3.14 as BOOLEAN) AND cast(3.0 as BOOLEAN))[#0] |
|   PARTITION: UNPARTITIONED                               |
|                                                          |
|   HAS_COLO_PLAN_NODE: false                              |
|                                                          |
|   VRESULT SINK                                           |
|      MYSQL_PROTOCAL                                      |
|                                                          |
|   0:VUNION(30)                                           |
|      constant exprs:                                     |
|          CAST(3.14 AS BOOLEAN) AND CAST(3.0 AS BOOLEAN)  |
+----------------------------------------------------------+
13 rows in set (0.01 sec)

mysql []>select 3.14 and 2.0;
+--------------------------------------------------+
| (cast(3.14 as BOOLEAN) AND cast(2.0 as BOOLEAN)) |
+--------------------------------------------------+
|                                                2 |
+--------------------------------------------------+

I think the problem here may be signature of and operator is not correct, it should not use boolean as operator.

zhiqiang-hhhh avatar Apr 19 '24 08:04 zhiqiang-hhhh

TeamCity be ut coverage result: Function Coverage: 35.42% (8922/25189) Line Coverage: 27.15% (73314/270072) Region Coverage: 26.25% (37843/144154) Branch Coverage: 23.08% (19290/83594) Coverage Report: http://coverage.selectdb-in.cc/coverage/e98c42d5c932a31f6568a722ea5995bdd9c2f9f6_e98c42d5c932a31f6568a722ea5995bdd9c2f9f6/report/index.html

doris-robot avatar Apr 19 '24 08:04 doris-robot