Skip to content

feat(spark): support ceil(decimal, scale) - #26914

Closed
ump45nose wants to merge 1 commit into
apache:mainfrom
ump45nose:feat/21560-spark-ceil-scale
Closed

ump45nose wants to merge 1 commit into
apache:mainfrom
ump45nose:feat/21560-spark-ceil-scale

Conversation

@ump45nose

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Spark ceil / ceiling accepts a second scale argument (RoundCeil). Only the one-arg form was implemented in datafusion-spark, and the matching cases in ceil.slt were commented out with a TODO pointing at this issue.

Earlier attempts (#21562, #21710, #24643) did not land. This PR focuses on the decimal path Spark declares for RoundCeil, and treats overflow as an error instead of wrapping (Spark raises NUMERIC_VALUE_OUT_OF_RANGE for extreme negative scales).

What changes are included in this PR?

  • SparkCeil accepts ceil(decimal, Int32 scale) with a constant scale.
  • Result type follows Spark RoundBase::dataType via return_field_from_args.
  • Checked arithmetic + precision check so results cannot silently wrap past the declared Decimal128 precision.
  • Re-enable the two PySpark-backed cases in ceil.slt. The positive-scale case uses the ceiling alias because sqlparser still routes ceil(x, 3) through CeilFloorKind::Scale, which the planner rejects before UDF resolution (same as today for FLOOR).

Non-decimal inputs with a scale are left for a follow-up (Spark casts them to decimal first).

What is the testing strategy for this PR?

  • Unit tests in ceil.rs for the PySpark cases, rounding toward +∞, no-op scales, carry, precision bounds, and overflow errors.
  • cargo test -p datafusion-spark --lib function::math::ceil
  • cargo test -p datafusion-sqllogictest --test sqllogictests -- spark/math/ceil

Are there any user-facing changes?

Spark sessions gain working ceil/ceiling with a decimal scale argument. No change to DataFusion's built-in one-arg ceil.

AI assistance

Assisted by AI tooling for drafting and iterating; I reviewed the Spark RoundCeil / RoundBase semantics, the overflow cases called out on #24643, and the test results before opening this PR.

Spark RoundCeil takes a decimal and a constant Int32 scale. Implement the
two-arg form on SparkCeil with result types from RoundBase::dataType, and
error on overflow instead of wrapping (matches Spark NUMERIC_VALUE_OUT_OF_RANGE).

Enable the previously commented PySpark cases in ceil.slt. Positive-scale
`ceil(...)` still hits the SQL planner's CeilFloorKind::Scale path; use the
`ceiling` alias for that case (documented in the .slt).

Closes apache#21560.
@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) spark Changes to datafusion-spark crate labels Oct 30, 2026
@2010YOUY01

Copy link
Copy Markdown
Member

Closing due to

It's impossible to contribute responsibly in such PR volume, please don't do automated contribution in this project.

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

Labels

spark Changes to datafusion-spark crate sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support 2-argument ceil(value, scale) for Spark

2 participants