Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](DECIMAL) error DECIMAL cat to BOOLEAN #33868

Closed
wants to merge 3 commits into from

Conversation

Mryange
Copy link
Contributor

@Mryange Mryange commented Apr 19, 2024

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

@doris-robot
Copy link

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.

@Mryange
Copy link
Contributor Author

Mryange commented Apr 19, 2024

run buildall

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@doris-robot
Copy link

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

@zhiqiang-hhhh
Copy link
Contributor

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.

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@Mryange
Copy link
Contributor Author

Mryange commented Apr 19, 2024

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
Copy link
Contributor Author

Mryange commented Apr 19, 2024

run buildall

@zhiqiang-hhhh
Copy link
Contributor

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.

@Mryange
Copy link
Contributor Author

Mryange commented Apr 19, 2024

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 |
+--------------------------------------------------+

@zhiqiang-hhhh
Copy link
Contributor

zhiqiang-hhhh commented Apr 19, 2024

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.

@doris-robot
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants