Skip to content

Conversation

@mrhhsg
Copy link
Member

@mrhhsg mrhhsg commented Jan 2, 2025

In the past, there were issues with converting double and decimal to boolean.
For example, a double value like 0.13 would first be cast to uint8, resulting in 0.
Then, it would be converted to bool, yielding 0 (incorrect, as the expected result is 1).

Similarly, decimal values were directly cast to uint8, leading to non-0/1 values for bool.
This issue arises because Doris internally uses uint8 to represent boolean.

before

mysql> select cast(40.123 as BOOLEAN);
+-------------------------+
| cast(40.123 as BOOLEAN) |
+-------------------------+
|                      40 |
+-------------------------+

now

mysql> select cast(40.123 as BOOLEAN);
+-------------------------+
| cast(40.123 as BOOLEAN) |
+-------------------------+
|                       1 |
+-------------------------+

What problem does this PR solve?

pick #44326
Related PR: #44326

Problem Summary:

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

In the past, there were issues with converting `double` and `decimal` to
`boolean`.
For example, a `double` value like 0.13 would first be cast to `uint8`,
resulting in 0.
Then, it would be converted to `bool`, yielding 0 (incorrect, as the
expected result is 1).

Similarly, `decimal` values were directly cast to `uint8`, leading to
non-0/1 values for `bool`.
This issue arises because Doris internally uses `uint8` to represent
`boolean`.

before
```
mysql> select cast(40.123 as BOOLEAN);
+-------------------------+
| cast(40.123 as BOOLEAN) |
+-------------------------+
|                      40 |
+-------------------------+
```

now
```
mysql> select cast(40.123 as BOOLEAN);
+-------------------------+
| cast(40.123 as BOOLEAN) |
+-------------------------+
|                       1 |
+-------------------------+
```
@Thearas
Copy link
Contributor

Thearas commented Jan 2, 2025

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

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@mrhhsg
Copy link
Member Author

mrhhsg commented Jan 2, 2025

run buildall

@yiguolei yiguolei added usercase Important user case type label and removed usercase Important user case type label labels Jan 2, 2025
@doris-robot
Copy link

TeamCity be ut coverage result:
Function Coverage: 36.38% (9550/26250)
Line Coverage: 27.92% (78788/282201)
Region Coverage: 26.62% (40465/152007)
Branch Coverage: 23.38% (20510/87712)
Coverage Report: http://coverage.selectdb-in.cc/coverage/17f959f9a9477b93457f04249fb423e0a50b41c7_17f959f9a9477b93457f04249fb423e0a50b41c7/report/index.html

@yiguolei yiguolei merged commit 7206ca3 into apache:branch-2.1 Jan 2, 2025
20 of 22 checks passed
@wm1581066 wm1581066 added the usercase Important user case type label label Jan 3, 2025
@yiguolei yiguolei mentioned this pull request Jan 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

usercase Important user case type label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants