← Back to Pull requests

[BugFix] Support cast of boolean to double and float in Calcite (#5987) #5993

Closed
unknown closed this pull request without merging on Nov 30, 2026 08:17 UTC
View on GitHub
unknown unknown commented on Nov 26, 2026 10:53 UTC
Author

Description


cast(<boolean> as double) and cast(<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)"), while cast(<boolean> as int) and cast(<boolean> as long) worked.

Root cause: Calcite's RexBuilder.makeCast rewrites a BOOLEAN → exact numeric cast (INTEGER/BIGINT) into CASE(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 reaches RexToLixTranslator, which emits Primitive.of(double.class).numberValueRoundDown(<boolean>) and the generated code does not compile.

Fix: ExtendedRexBuilder.makeCast now rewrites BOOLEAN → approximate numeric (DOUBLE, FLOAT/REAL) casts the same way Calcite does for exact numerics: CASE(b, 1.0, 0.0), wrapped in CASE(IS NOT NULL(b), ..., null) when the input is nullable. So true → 1.0, false → 0.0, and null stays null. This matches the int/long casts, the v2 engine (TypeCastOperators maps boolean to 1D/0D and 1f/0f), and the documented v?1:0 rule in docs/user/ppl/functions/conversion.md, so no doc change is needed.

Related Issues


Resolves #5987

Check List


  • New functionality includes testing.

  • - Unit tests in ExtendedRexBuilderTest for the rewritten expression (nullable and non-null boolean, DOUBLE and REAL).
    - Unit tests in CalcitePPLCastFunctionTest that execute cast(... as int/double/float) on true, false and null booleans and on boolean literals. Both fail on main with 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.yml with true, false and missing values.
  • New functionality has been documented.

  • - [ ] New functionality has javadoc added.
    - [ ] New functionality has a user manual doc added.
  • New PPL command checklist all confirmed.

  • API changes companion pull request created.

  • Commits are signed per the DCO using --signoff or -s.

  • Public documentation issue/PR created.
  • 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.

    Diff: 360 lines (+270 / -90) across 4 files Reviewer: Swiddis Review duration: 5604m
    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
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.6% (MEDIUM) · Higher = larger blast radius
    42.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.8% · Safe to merge
    16.8%