[BugFix] Support cast of boolean to double and float in Calcite (#5987) #5993
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 360 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 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.352
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #5993"
general
weight: 0.35
Swiddis
Description
cast(<boolean> as double)andcast(<boolean> as float)failed with a 500 (No applicable constructor/method found for actual parameters "boolean"; candidates are: "public java.lang.Object org.apache.calcite.linq4j.tree.Primitive.numberValueRoundDown(java.lang.Number)"), whilecast(<boolean> as int)andcast(<boolean> as long)worked.Root cause: Calcite's
RexBuilder.makeCastrewrites a BOOLEAN → exact numeric cast (INTEGER/BIGINT) intoCASE(b, 1, 0), which is why the int/long casts work. There is no such rewrite for approximate numeric targets, so a BOOLEAN → DOUBLE/REAL cast reachesRexToLixTranslator, which emitsPrimitive.of(double.class).numberValueRoundDown(<boolean>)and the generated code does not compile.Fix:
ExtendedRexBuilder.makeCastnow rewrites BOOLEAN → approximate numeric (DOUBLE, FLOAT/REAL) casts the same way Calcite does for exact numerics:CASE(b, 1.0, 0.0), wrapped inCASE(IS NOT NULL(b), ..., null)when the input is nullable. Sotrue→1.0,false→0.0, andnullstaysnull. This matches the int/long casts, the v2 engine (TypeCastOperatorsmaps boolean to1D/0Dand1f/0f), and the documentedv?1:0rule indocs/user/ppl/functions/conversion.md, so no doc change is needed.Related Issues
Resolves #5987
Check List
- Unit tests in
ExtendedRexBuilderTestfor the rewritten expression (nullable and non-null boolean, DOUBLE and REAL).- Unit tests in
CalcitePPLCastFunctionTestthat executecast(... as int/double/float)on true, false and null booleans and on boolean literals. Both fail onmainwith the codegen error from the issue.- Re-enabled the FLOAT and DOUBLE assertions in
CalcitePPLCastFunctionIT.testCastBOOLEAN, which were commented out with a TODO for this codegen error.- YAML REST test
issues/5987.ymlwith true, false and missing values.- [ ] New functionality has javadoc added.
- [ ] New functionality has a user manual doc added.
--signoffor-s.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.