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 22:15:04 UTC
[PR] [fix](nereids) Widen FLOAT literals in binary when folding to DOUBLE or DECIMAL [doris]
abhinav-phi opened a new pull request, #68730:
URL: https://github.com/apache/doris/pull/68730
### What problem does this PR solve?
Issue Number: close #68721
Related PR: None
Problem Summary:
`FloatLiteral.uncheckedCastTo(DOUBLE)` did `Double.parseDouble(String.valueOf(value))` and the
decimal path did `new BigDecimal(Float.toString(value))`. Both go through the shortest decimal
string that represents the float, which throws away the information BE keeps: a `FLOAT` column
widened to `DOUBLE` is the exact binary widening of the float32 value, not the decimal literal
the user typed.
```sql
SELECT CAST(CAST(0.1 AS FLOAT) AS DOUBLE), -- FE fold: 0.1
CAST(CAST(0.1 AS FLOAT) AS DECIMAL(20,10)); -- FE fold: 0.1000000000
-- BE (column path, or SET debug_skip_fold_constant = true):
-- 0.10000000149011612 and 0.1000000015
```
So the same expression evaluated as a constant and as a column produced different values, which
is what the report shows.
The fix widens in binary: `(double) value` for the `DOUBLE` target and `new BigDecimal((double) value)`
for the decimal targets. That is exactly what a Float32 -> Float64 cast does on the BE side, so the
folded literal now equals the executed value. Integral and date targets keep using
`getValue().toString()` through `FractionalLiteral`/`NumericLiteral` and are unchanged, so
`CAST(CAST(0.1 AS FLOAT) AS INT)` and friends behave as before.
One existing assertion in `FloatLiteralTest` encoded the old behaviour
(`(float) 234.567 -> 234.567`); it is updated to the widened value
(`(double) (float) 234.567` = `234.56700134277344`), which is what BE returns for that float.
### 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:
`FloatLiteralTest` now asserts both reported cases (`0.1` widened to `DOUBLE`, and
`0.1` cast to `DECIMAL(20,10)` -> `0.1000000015`) plus the corrected `234.567` expectation.
Red, on `master` with only the test changes applied:
```
[ERROR] FloatLiteralTest.testUncheckedCastTo:181 expected: <234.56700134277344> but was: <234.567>
[ERROR] Tests run: 66, Failures: 3, Errors: 0, Skipped: 0
```
Green, with the source fix:
```
[INFO] Tests run: 3, Failures: 0, Errors: 0 - FloatLiteralTest
[INFO] Tests run: 2, Failures: 0, Errors: 0 - DoubleLiteralTest
[INFO] Tests run: 2, Failures: 0, Errors: 0 - DecimalLiteralTest
[INFO] Tests run: 2, Failures: 0, Errors: 0 - CompareLiteralTest
[INFO] Tests run: 23, Failures: 0, Errors: 0 - CastTest
[INFO] Tests run: 1, Failures: 0, Errors: 0 - ConstantProjectionFoldingTest
[INFO] Tests run: 4, Failures: 0, Errors: 0 - NumericArithmeticTest
[INFO] Tests run: 2, Failures: 0, Errors: 0 - org.apache.doris.analysis.FloatLiteralTest
```
Command (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=FloatLiteralTest,DoubleLiteralTest,DecimalLiteralTest,CompareLiteralTest,FoldConstantTest,ConstantProjectionFoldingTest,NumericArithmeticTest,CastTest
```
About the two remaining `FoldConstantTest` failures (`testDateConstructFunction:1552`,
`testFoldString:581`): they are **pre-existing on this machine and unrelated to this change**.
I ran `FoldConstantTest` alone on a pristine `master` worktree with every edit of mine stashed
and got the identical two failures:
```
[ERROR] FoldConstantTest.testDateConstructFunction:1552 expected: <'1977-06-03 17:57:24'> but was: <'1977-06-03 15:27:24'>
[ERROR] FoldConstantTest.testFoldString:581 expected: <'2025-10-27 14:58:08.100000'> but was: <'2025-10-27 12:28:08.100000'>
[ERROR] Tests run: 27, Failures: 2, Errors: 0, Skipped: 0
```
They are timestamp assertions that depend on the session time zone of the environment, and
neither touches float/double/decimal folding.
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 -->
Folding `CAST(<float literal> AS DOUBLE)` and `CAST(<float literal> AS DECIMAL(p,s))` now
produces the same value the BE produces for a `FLOAT` column, i.e. `CAST(CAST(0.1 AS FLOAT)
AS DOUBLE)` is `0.10000000149011612` instead of `0.1`. The old folded value was the one that
was wrong. No other cast target changes.
- 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 updated assertions. I read and reviewed
every line myself, ran the FE unit tests above on the exact commit in this branch, including the
pristine-master control run quoted above, and I take responsibility for the result. The production
change is two expressions in one file.
--
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](constant folding) Widen FLOAT literals in binary when folding to DOUBLE or DECIMAL [doris]
Posted by "morrySnow (via GitHub)" <gi...@apache.org>.
morrySnow commented on PR #68730:
URL: https://github.com/apache/doris/pull/68730#issuecomment-6073813871
@abhinav-phi please handle the conflict
--
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](constant folding) Widen FLOAT literals in binary when folding to DOUBLE or DECIMAL [doris]
Posted by "abhinav-phi (via GitHub)" <gi...@apache.org>.
abhinav-phi commented on PR #68730:
URL: https://github.com/apache/doris/pull/68730#issuecomment-6098825246
@morrySnow conflict resolved in dbfc088bf2, the branch is mergeable again.
master added a NaN sign guard in FloatLiteral.uncheckedCastTo while this branch replaced the string based widening with a binary one, so both edits landed on the same lines. i kept the guard from master for the NaN case and widened every other value in binary. behaviour for a NaN is the same either way, a float to double widening in java keeps the sign of a NaN, i verified that separately before picking this shape rather than deleting the guard.
the diff against master is now just the two files, FloatLiteral.java and FloatLiteralTest.java, and the test still asserts both reported cases. the runs on the new head may need the usual trigger again, thanks.
--
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) Widen FLOAT literals in binary when folding to DOUBLE or DECIMAL [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #68730:
URL: https://github.com/apache/doris/pull/68730#issuecomment-5985026511
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
Re: [PR] [fix](constant folding) Widen FLOAT literals in binary when folding to DOUBLE or DECIMAL [doris]
Posted by "abhinav-phi (via GitHub) via commits" <co...@doris.apache.org>.
abhinav-phi commented on PR #68730:
URL: https://github.com/apache/doris/pull/68730#issuecomment-7013742224
hi @morrySnow, your earlier review on this got dismissed when the branch was updated and it has been quiet since.. the pr is the float widening fix for issue #68721 with unit tests included.. could you take a look when you get a chance.. thanks
--
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