Skip to content

fix: exclude precision-losing integer-to-float conversions from CastExpr::check_bigger_cast (#23808)#23809

Open
getChan wants to merge 1 commit into
apache:mainfrom
getChan:fix-23808-check-bigger-cast
Open

fix: exclude precision-losing integer-to-float conversions from CastExpr::check_bigger_cast (#23808)#23809
getChan wants to merge 1 commit into
apache:mainfrom
getChan:fix-23808-check-bigger-cast

Conversation

@getChan

@getChan getChan commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

ref. #23807

CastExpr::check_bigger_cast is used to determine whether a cast is a widening (order-preserving) conversion. Currently, it classifies Int32 -> Float32, UInt32 -> Float32, Int64 -> Float64, and UInt64 -> Float64 as widening casts.

However, integer-to-float conversions for 32-bit and 64-bit integers lose precision when values exceed the mantissa bit limit (24 bits for Float32, 53 bits for Float64). For example:
16_777_216_i32 as f32 == 16_777_217_i32 as f32 (both yield 16777216.0f32).

Because distinct integer inputs can collapse to the same float output, these casts are not strictly 1-to-1 (injective) and can break suffix sort key ordering in multi-column ordering analysis (e.g. [CAST(a AS Float32), b]).

What changes are included in this PR?

  • Updated CastExpr::check_bigger_cast to exclude precision-losing integer-to-float conversions (Int32/UInt32 -> Float32 and Int64/UInt64 -> Float64).
  • Added unit test test_check_bigger_cast_precision_loss to verify precision-losing casts return false while exact conversions (Int16 -> Float32, Int32 -> Float64, etc.) continue to return true.

Are these changes tested?

Yes, new unit test test_check_bigger_cast_precision_loss in cast.rs.

Are there any user-facing changes?

No breaking API changes. Internal optimizer behavior fix.

@github-actions github-actions Bot added the physical-expr Changes to the physical-expr crates label Jul 22, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@f33dcec). Learn more about missing BASE report.
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #23809   +/-   ##
=======================================
  Coverage        ?   80.71%           
=======================================
  Files           ?     1089           
  Lines           ?   368916           
  Branches        ?   368916           
=======================================
  Hits            ?   297778           
  Misses          ?    53379           
  Partials        ?    17759           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-expr Changes to the physical-expr crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix precision loss in CastExpr::check_bigger_cast for integer-to-float conversions

2 participants