[fix](cast) Use the binary value when casting FLOAT/DOUBLE literals to integrals #68733
All Vouch review confidence checks passed
Residual risk 0.35 = Change Risk (0.59) × (1 − Review Confidence (0.41)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.59 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #68733"
general
weight: 0.35
abhinav-phi
What problem does this PR solve?
Issue Number: close #68722
Related PR: #68729 (same file, different method — that one is the BOOLEAN branch, this is the
integral branch; whichever lands first the other rebases without conflict)
Problem Summary:
FractionalLiteral.uncheckedCastTo(<integral type>)built its working decimal withnew BigDecimal(value.toString()). For aFloat/Doublethat is the shortest decimalrepresentation of the value, not the value itself, so the folded integral is derived from the
text rather than from the binary magnitude. BE converts the binary value.
1e38as a double really is99999999999999997748809823456034029568;Double.toString(1e38)is"1.0E38", andnew BigDecimal("1.0E38")is exactly 10^38 — hence the mismatch, and a constantfold that LARGEINT cannot even represent round-trip.
The fix keeps the decimal-string behaviour for
BigDecimalsources (decimal literals are alreadyexact) and uses the binary value for
Float/Doublesources, which is what BE does. Truncationtoward zero, the finite check and the overflow check are unchanged, so
CAST(12.999 AS INT) = 12,CAST(-12.999 AS BIGINT) = -12and out-of-range values still throwCastException— all of which the existing assertions still cover.The same argument applies one step earlier, in the overflow precheck, which the review pointed
out:
checkedCastTocallsLiteral.numericOverflow(getStringValue(), targetType), andgetStringValue()is again the printed value.DOUBLE-2^63 prints-9.223372036854776E18, i.e.-9223372036854776000, which is below
BIGINT_MIN, so the precheck declared overflow and the castfolded to NULL for a value that is exactly -9223372036854775808 and that BE accepts.
FLOAT-2^31to INT is the same shape (
-2.14748365E9). For the two floating literal kinds the precheck nowtests the binary value.
Literal.getDouble()cannot be used for that - it parsesgetValue().toString(), which for aFloatis the 9-digit shortest form again - so theNumberiswidened directly. The infinity/NaN names still return early above, so
BigDecimal(double)is neverhanded a non-finite value, and integer and decimal literals keep the string path.
The date-like branch of the same method still uses
getValue().toString(); aDOUBLE->DATEfold goes through a day-number encoding where the decimal-vs-binary question needs its own look at
BE, so it is deliberately left out of this change.
Release note
None
Check List (For Author)
- [x] Regression test (
test_cast.outrows re-derived, see below)- [x] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
New
DoubleLiteralTest.testCastToIntegralUsesTheBinaryValueasserts the reported case(
CAST(1e38 AS LARGEINT)->99999999999999997748809823456034029568), that the exactlyrepresentable case is unchanged (
CAST(1e9 AS LARGEINT)->1000000000), that ordinarytruncation still trims toward zero (
CAST(-12.999 AS BIGINT)->-12) and that an out-of-rangemagnitude still raises
CastExceptioninstead of saturating.Red, on
masterwith only the test added:Green, with the fix (whole net):
The precheck fix has its own pair of tests:
DoubleLiteralTestassertscheckedCastTo(BIGINT)of -2^63 givesLong.MIN_VALUEandFloatLiteralTestassertscheckedCastTo(INT)of -2^31 givesInteger.MIN_VALUE.P0 Regression/cloud_p0were red on the previous head, and in TeamCity builds 1064115 and1064117 the only non-muted failing occurrence in both is
query_p0.cast.test_cast.test_cast; everyother failure in those builds is reported
currentlyMuted=true. That suite is exactly what thisbehaviour change moves, so its recorded rows are updated in the third commit. They were not typed
in. Every select list there is a pure constant expression, so the cluster answer is the FE fold; the
rows were produced by folding the expressions parsed out of
test_cast.groovythroughFoldConstantRuleOnFEon this branch, and each of the 40 cells was then re-derived independentlyfrom the exact IEEE-754 expansion of the literal (round-to-nearest for the SQL FLOAT/DOUBLE cast,
truncation toward zero for the integral cast, NULL out of range). The two agree on all 40 cells on
this branch and disagree on the 12 cells master still folds through the printed value. Before
trusting it as a re-recorder the same probe was run against a pristine
origin/masterworktree,where it reproduces the previously recorded rows for all ten sections (0 of 10 change), and the
value CI itself printed for the failing cell,
9223372036854774784, is what this patch writes.Review finding 4226508929 (a nested
FLOAT->DOUBLE->LARGEINTfold) is #68730's file:FloatLiteral.uncheckedCastTo(DOUBLE)is what that PR changes, so it is not touched here onpurpose; the case belongs there once that lands.
Two
FoldConstantTestfailures remain in the net; they are pre-existing on this machine andunrelated — they reproduce identically on pristine
masterwith every edit of mine stashed, andthey are session-time-zone dependent timestamp assertions:
Command (project flags from
run-fe-ut.sh):Environment: JDK 17.0.20 (Temurin), Maven 3.9.16, thrift 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.- [ ] No.
- [x] Yes. <!-- Explain the behavior change -->
Folding a
FLOAT/DOUBLEliteral to an integral type now uses the binary value, both for theoverflow precheck and for the converted value, so cases where the shortest decimal differs from
the binary magnitude (the reported
1e38-> LARGEINT) return the BE result, and boundaryliterals that print outside a range but sit exactly on its edge (-2^63 -> BIGINT, -2^31 -> INT,
-2^127 -> LARGEINT) now fold to the value instead of NULL, while values that really are out of
range (2^63 -> BIGINT, 2^127 -> LARGEINT) now fold to NULL instead of a printed decimal that
happened to fit. Truncation toward zero and the finite check are unchanged.
- [x] No.
- [ ] Yes. <!-- Add document PR link here. -->
Check List (For Reviewer who merge this PR)
AI assistance disclosure
An AI coding agent was used to draft this change and the new test. 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 for
FoldConstantTest), and I take responsibility for the result.