Skip to content

fix: avoid query failures from inferred numeric cast bounds - #25528

Merged
kosiew merged 8 commits into
apache:mainfrom
haohuaijin:fix/25524-inferred-cast-bounds
Oct 6, 2026
Merged

kosiew merged 8 commits into
apache:mainfrom
haohuaijin:fix/25524-inferred-cast-bounds

Conversation

@haohuaijin

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #25524.
Related to #25407 and #22028.

Rationale for this change

A valid query can fail when an inferred numeric interval extends beyond the target CAST type, even though every runtime value fits. For example, an expression that always evaluates to zero can have an estimated upper bound of 1000 and fail when cast to TINYINT during planning.

What changes are included in this PR?

Use safe Arrow casts for numeric interval endpoints in Interval::cast_to, independently of the runtime cast error policy. An endpoint that cannot be represented becomes unbounded, while a valid opposite endpoint is retained. Non-numeric conversions continue to honor the supplied cast options, and errors returned by the cast kernel are still propagated.

What is the testing strategy for this PR?

  • Add regression cases to the existing cast.slt for positive and negative inferred overflow, ordinary CAST runtime errors, and TRY_CAST runtime NULL results.
  • Add unit coverage for numeric narrowing, signed/unsigned conversions, decimal precision and scale changes, fractional values, existing unbounded endpoints, and non-numeric error handling.
  • Check sampled value containment across 14 numeric types with both safe option settings.
  • Validated expr-common unit tests, physical-expr and pruning unit tests, and six relevant SLT files covering casts, filter ordering, and filter pushdown.

Are there any user-facing changes?

Valid queries no longer fail solely because inferred numeric cast endpoints are out of range. Runtime CAST and TRY_CAST behavior is unchanged.

@github-actions github-actions Bot added logical-expr Logical plan and expressions sqllogictest SQL Logic Tests (.slt) labels Sep 20, 2026
@codecov-commenter

codecov-commenter commented Sep 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.70%. Comparing base (c0e872f) to head (0ee0f7f).

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #25528    +/-   ##
========================================
  Coverage   82.69%   82.70%            
========================================
  Files        1147     1147            
  Lines      447348   447535   +187     
  Branches   447348   447535   +187     
========================================
+ Hits       369936   370118   +182     
- Misses      54999    55005     +6     
+ Partials    22413    22412     -1     

☔ 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.

@haohuaijin

haohuaijin commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @kosiew, would you mind taking a look at this inferred cast bounds fix following #25234? Thanks!

@kosiew kosiew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haohuaijin,

Thanks for working on this. The change looks good to me. Numeric interval-bound casts now handle out-of-range inferred endpoints conservatively without changing runtime CAST and TRY_CAST behavior, and the added coverage exercises the relevant edge cases.

@haohuaijin

Copy link
Copy Markdown
Contributor Author

Thanks @kosiew

@kosiew

kosiew commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

🚀
@haohuaijin
Thank you for your contribution.

@kosiew
kosiew added this pull request to the merge queue Oct 6, 2026
Merged via the queue into apache:main with commit 827ca29 Oct 6, 2026
42 checks passed
@haohuaijin
haohuaijin deleted the fix/25524-inferred-cast-bounds branch October 6, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

logical-expr Logical plan and expressions sqllogictest SQL Logic Tests (.slt) v56.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Narrowing casts of inferred interval endpoints can reject valid queries

3 participants