You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by "abhinav-phi (via GitHub)" <gi...@apache.org> on 2026/10/04 21:51:49 UTC
[PR] [fix](nereids) Compare fractional literal values in their own precision when casting to BOOLEAN [doris]
abhinav-phi opened a new pull request, #68729:
URL: https://github.com/apache/doris/pull/68729
### What problem does this PR solve?
Issue Number: close #68714
Related PR: None
Problem Summary:
`FractionalLiteral.uncheckedCastTo(BooleanType)` tested the value with
`((Number) value).floatValue() == 0`. For a `DOUBLE` literal, narrowing to `float` first
flushes every magnitude below the float32 rounding limit (about `7e-46`, i.e. half the
smallest positive float32 subnormal) to `0.0f`, so a nonzero double folded to `FALSE`:
```sql
SELECT CAST(5e-324 AS BOOLEAN); -- FE fold: FALSE
SELECT IF(1e-300, 't', 'f'); -- FE fold: f
```
The same value read from a column goes through BE, where
`be/src/exprs/function/cast/cast_to_boolean.h` compares the original `Float64` against zero
and returns `TRUE`. So a constant expression and a column expression disagreed, and a
constant `WHERE` predicate built from such a literal could drop every row.
The fix compares in the value's own precision, `doubleValue() == 0`. Widening `float` to
`double` is exact, so the `FloatLiteral` path keeps its previous behaviour; only the `DOUBLE`
path changes, which is the one that was wrong. `NaN` and both infinities still fold to
`TRUE` as before, which is what the existing assertions in `DoubleLiteralTest` require.
### Release note
None
### Check List (For Author)
- Test <!-- At least one of them must be included. -->
- [ ] Regression test
- [x] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
Five assertions were added to the existing boolean block of
`fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/literal/DoubleLiteralTest.java`
covering `Double.MIN_VALUE`, `-Double.MIN_VALUE`, `1e-300`, `1e-46` and the exact literal
from the report, `5e-324`.
Red, on `master` (`7ac0eb2f`) with only the source line reverted:
```
[ERROR] DoubleLiteralTest.testUncheckedCastTo:61 expected: <true> but was: <false>
[ERROR] Tests run: 7, Failures: 1, Errors: 0, Skipped: 0
[INFO] BUILD FAILURE
```
Green, with this change applied:
```
[INFO] Tests run: 2, Failures: 0 - DoubleLiteralTest
[INFO] Tests run: 3, Failures: 0 - FloatLiteralTest
[INFO] Tests run: 2, Failures: 0 - org.apache.doris.analysis.FloatLiteralTest
[INFO] Tests run: 7, Failures: 0, Errors: 0, Skipped: 0
[INFO] BUILD SUCCESS
```
Command used (the project's own flags, from `run-fe-ut.sh`):
```
mvn test -pl fe-core -am -Dcheckstyle.skip=true -DfailIfNoTests=false \
-Dmaven.build.cache.enabled=false -Dtest=DoubleLiteralTest,FloatLiteralTest
```
Environment: JDK 17.0.20 (Temurin), Maven 3.9.16, thrift compiler 0.24.0 from the prebuilt
thirdparty package, Ubuntu 22.04 under WSL2.
Style gate: `mvn -pl fe-core checkstyle:check` -> `You have 0 Checkstyle violations.`
- Behavior changed:
- [ ] No.
- [x] Yes. <!-- Explain the behavior change -->
Constant folding of a nonzero `DOUBLE` whose magnitude is below the float32 rounding
limit now yields `TRUE` when cast to `BOOLEAN` (and in predicates such as `IF`, `CASE`,
`AND`, `WHERE`), instead of `FALSE`. This matches the BE result for the same value and
matches the column path. No other cast target is touched.
- Does this need documentation?
- [x] No.
- [ ] Yes. <!-- Add document PR link here. -->
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label
### AI assistance disclosure
An AI coding agent was used to draft this change and the added assertions. I read and
reviewed every line myself, ran the FE unit tests above on the exact commit in this branch,
and I take responsibility for the result. The change is one line of production code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](cast) Compare fractional literal values in their own precision when casting to BOOLEAN [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #68729:
URL: https://github.com/apache/doris/pull/68729#issuecomment-6074041698
<details>
<summary>TPC-H: <b>Total hot run time: 29141 ms</b></summary>
```
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 6db56cb0e69356d3001f4435a4455084904e7fb9, data reload: false
------ Round 1 ----------------------------------
============================================
q1 17571 5678 5586 5586
q2 2079 300 251 251
q3 10265 1400 844 844
q4 4675 473 352 352
q5 7435 795 536 536
q6 190 185 155 155
q7 777 796 602 602
q8 9251 1384 1086 1086
q9 5717 4491 4443 4443
q10 6835 1298 1019 1019
q11 447 266 241 241
q12 634 402 287 287
q13 18052 3084 2396 2396
q14 281 278 252 252
q15 q16 744 728 665 665
q17 1176 751 591 591
q18 7168 6225 6202 6202
q19 1263 968 621 621
q20 392 343 234 234
q21 5975 2483 2609 2483
q22 407 359 295 295
Total cold run time: 101334 ms
Total hot run time: 29141 ms
----- Round 2, with runtime_filter_mode=off -----
============================================
q1 6714 6635 6647 6635
q2 758 614 555 555
q3 5522 5722 5319 5319
q4 2016 2182 1564 1564
q5 5858 5698 5824 5698
q6 235 185 144 144
q7 2257 1981 1850 1850
q8 3119 2669 2714 2669
q9 8222 8085 7894 7894
q10 3692 3606 3259 3259
q11 584 404 371 371
q12 673 705 501 501
q13 2750 3092 2405 2405
q14 296 289 267 267
q15 q16 672 683 619 619
q17 7682 7002 6965 6965
q18 13052 12238 13036 12238
q19 915 781 791 781
q20 2175 2201 1936 1936
q21 5750 4683 4781 4683
q22 508 474 408 408
Total cold run time: 73450 ms
Total hot run time: 66761 ms
```
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](cast) Compare fractional literal values in their own precision when casting to BOOLEAN [doris]
Posted by "morrySnow (via GitHub)" <gi...@apache.org>.
morrySnow merged PR #68729:
URL: https://github.com/apache/doris/pull/68729
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](cast) Compare fractional literal values in their own precision when casting to BOOLEAN [doris]
Posted by "morrySnow (via GitHub)" <gi...@apache.org>.
morrySnow commented on PR #68729:
URL: https://github.com/apache/doris/pull/68729#issuecomment-6073826297
run buildall
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](cast) Compare fractional literal values in their own precision when casting to BOOLEAN [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #68729:
URL: https://github.com/apache/doris/pull/68729#issuecomment-6076243946
# FE UT Coverage Report
Increment line coverage ` 100.00% (1/1)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/68729_6db56cb0e69356d3001f4435a4455084904e7fb9/fe_increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/68729_6db56cb0e69356d3001f4435a4455084904e7fb9/fe_report/index.html)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](cast) Compare fractional literal values in their own precision when casting to BOOLEAN [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #68729:
URL: https://github.com/apache/doris/pull/68729#issuecomment-6076006863
# FE Regression Coverage Report
Increment line coverage ` 9.09% (1/11)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/68729_6db56cb0e69356d3001f4435a4455084904e7fb9_merge_fe/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/68729_6db56cb0e69356d3001f4435a4455084904e7fb9_merge_fe/report/index.html)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](cast) Compare fractional literal values in their own precision when casting to BOOLEAN [doris]
Posted by "morrySnow (via GitHub)" <gi...@apache.org>.
morrySnow commented on PR #68729:
URL: https://github.com/apache/doris/pull/68729#issuecomment-6073825399
/review
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](cast) Compare fractional literal values in their own precision when casting to BOOLEAN [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #68729:
URL: https://github.com/apache/doris/pull/68729#issuecomment-6074140009
<details>
<summary>TPC-DS: <b>Total hot run time: 151406 ms</b></summary>
```
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 6db56cb0e69356d3001f4435a4455084904e7fb9, data reload: false
query5 4298 549 461 461
query6 425 207 201 201
query7 4801 438 221 221
query8 316 183 163 163
query9 8790 4002 3999 3999
query10 466 311 250 250
query11 6003 3417 3179 3179
query12 136 90 82 82
query13 1255 424 321 321
query14 6565 4828 4545 4545
query14_1 4298 4202 4271 4202
query15 210 209 189 189
query16 963 502 370 370
query17 861 656 555 555
query18 2429 429 311 311
query19 199 171 135 135
query20 80 81 79 79
query21 211 132 112 112
query22 12900 13136 12856 12856
query23 13302 12493 12130 12130
query23_1 12272 12155 12188 12155
query24 7110 817 464 464
query24_1 467 486 477 477
query25 532 417 369 369
query26 1312 260 139 139
query27 2764 438 274 274
query28 4612 1932 1924 1924
query29 1579 621 427 427
query30 288 213 185 185
query31 874 764 648 648
query32 143 92 84 84
query33 508 293 235 235
query34 910 863 492 492
query35 744 760 654 654
query36 850 808 739 739
query37 135 104 84 84
query38 1781 1779 1709 1709
query39 717 746 696 696
query39_1 662 664 674 664
query40 212 113 95 95
query41 66 68 63 63
query42 82 83 79 79
query43 365 377 327 327
query44 1280 678 686 678
query45 181 175 162 162
query46 839 965 563 563
query47 2939 3030 2938 2938
query48 292 300 209 209
query49 573 389 300 300
query50 681 270 216 216
query51 10229 10269 10172 10172
query52 80 77 68 68
query53 188 207 152 152
query54 232 188 177 177
query55 71 63 61 61
query56 225 218 199 199
query57 1608 1592 1555 1555
query58 274 295 245 245
query59 2375 2400 2149 2149
query60 276 219 219 219
query61 144 145 144 144
query62 393 340 285 285
query63 193 160 169 160
query64 2727 912 767 767
query65 3410 3370 3371 3370
query66 1790 423 304 304
query67 20158 20053 19862 19862
query68 2974 984 593 593
query69 374 290 255 255
query70 914 821 808 808
query71 298 226 199 199
query72 2697 2589 2255 2255
query73 505 525 296 296
query74 4566 4473 4285 4285
query75 2313 2305 1933 1933
query76 2297 1087 594 594
query77 354 396 301 301
query78 9063 8967 8489 8489
query79 866 890 507 507
query80 505 421 340 340
query81 535 325 274 274
query82 583 140 111 111
query83 294 201 177 177
query84 313 112 98 98
query85 811 427 369 369
query86 315 242 235 235
query87 2002 1982 1829 1829
query88 3592 2689 2658 2658
query89 346 311 252 252
query90 1885 179 178 178
query91 160 155 123 123
query92 101 87 79 79
query93 977 978 568 568
query94 457 316 284 284
query95 611 412 322 322
query96 662 527 228 228
query97 2465 2434 2305 2305
query98 154 154 142 142
query99 776 762 647 647
Total cold run time: 233095 ms
Total hot run time: 151406 ms
```
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](cast) Compare fractional literal values in their own precision when casting to BOOLEAN [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #68729:
URL: https://github.com/apache/doris/pull/68729#issuecomment-6074188610
<details>
<summary>ClickBench: <b>Total hot run time: 24.31 s</b></summary>
```
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 6db56cb0e69356d3001f4435a4455084904e7fb9, data reload: false
query1 0.00 0.00 0.00
query2 0.10 0.05 0.05
query3 0.26 0.11 0.12
query4 1.61 0.12 0.12
query5 0.28 0.22 0.24
query6 1.17 0.69 0.69
query7 0.04 0.01 0.00
query8 0.05 0.04 0.04
query9 0.41 0.36 0.36
query10 0.58 0.55 0.59
query11 0.21 0.15 0.14
query12 0.19 0.15 0.14
query13 0.50 0.49 0.50
query14 0.98 0.98 0.95
query15 0.62 0.60 0.60
query16 0.36 0.36 0.31
query17 1.16 1.15 1.09
query18 0.23 0.21 0.21
query19 2.04 2.03 1.92
query20 0.02 0.01 0.01
query21 15.48 0.26 0.15
query22 4.36 0.05 0.05
query23 16.29 0.33 0.12
query24 3.10 0.72 0.40
query25 0.11 0.04 0.06
query26 1.68 0.25 0.14
query27 0.05 0.03 0.04
query28 2.00 0.67 0.43
query29 12.53 4.14 3.25
query30 0.29 0.14 0.13
query31 2.78 0.58 0.35
query32 3.22 0.61 0.53
query33 3.17 3.26 3.27
query34 15.54 3.97 3.36
query35 3.38 3.34 3.31
query36 0.55 0.47 0.42
query37 0.10 0.06 0.07
query38 0.05 0.04 0.04
query39 0.04 0.03 0.02
query40 0.17 0.14 0.14
query41 0.08 0.03 0.03
query42 0.04 0.03 0.02
query43 0.04 0.04 0.03
Total cold run time: 95.86 s
Total hot run time: 24.31 s
```
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](nereids) Compare fractional literal values in their own precision when casting to BOOLEAN [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #68729:
URL: https://github.com/apache/doris/pull/68729#issuecomment-5984784484
Thank you for your contribution to Apache Doris.
Don't know what should be done next? See [How to process your PR](https://doris.apache.org/community/how-to-contribute/review-and-ci).
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?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org