Skip to content

feat: Implement preimage for ceil and round functions#22656

Open
kumarlokesh wants to merge 1 commit into
apache:mainfrom
kumarlokesh:feature/preimage-for-ceil-round-funcs
Open

feat: Implement preimage for ceil and round functions#22656
kumarlokesh wants to merge 1 commit into
apache:mainfrom
kumarlokesh:feature/preimage-for-ceil-round-funcs

Conversation

@kumarlokesh
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

floor(col) = N is already rewritten via ScalarUDFImpl::preimage so that
predicates push into Parquet row-group statistics. ceil and round admit
the same rewrite but have boundary conventions that don't fit the API's
half-open [lower, upper) form: ceil(x) = N is (N-1, N], and round(x) = N
is sign-dependent under half-away-from-zero. Both can be expressed in
[lower, upper) form by shifting closed boundaries with f::next_up()

What changes are included in this PR?

  • CeilFunc::preimage - Float32/Float64 and all four Decimal variants.
  • RoundFunc::preimage - Float32/Float64 (with optional literal dp) and all
    four Decimal variants for dp = 0.
  • Helper functions ceil_preimage_float / ceil_preimage_decimal in ceil.rs,
    round_preimage_float / round_preimage_decimal in round.rs.
  • A small FloatExt trait in each file bridging num_traits::Float to
    f32::next_up() / f64::next_up().

No changes to the preimage API, the simplifier, or any optimizer rule.

Are these changes tested?

Yes.

  • Unit tests cover positive / negative / zero / non-integer / null / overflow /
    non-finite cases for both float and decimal variants.
  • SLT tests (ceil_preimage.slt, round_preimage.slt) cover data correctness
    and EXPLAIN output for all six comparison operators plus
    IS (NOT) DISTINCT FROM and IN/NOT IN.

Are there any user-facing changes?

No public API change. The optimization is transparent and predicate semantics
are preserved exactly.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement preimage for ceil and round functions

1 participant