Skip to content

fixing negative power to zero - #22277

Merged
Dandandan merged 2 commits into
apache:mainfrom
raushanprabhakar1:feat/22272-fix-negative-power-zero
May 19, 2026
Merged

fixing negative power to zero#22277
Dandandan merged 2 commits into
apache:mainfrom
raushanprabhakar1:feat/22272-fix-negative-power-zero

Conversation

@raushanprabhakar1

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

PostgreSQL rejects power(0::float8, negative::float8) because zero raised to a negative power is undefined. DataFusion used f64::powf, which returns infinity for that case. This aligns float (and related decimal float paths) with PostgreSQL’s domain semantics.

What changes are included in this PR?

  • Added float64_power_checked to error when base == 0.0 and exp < 0.0 with message zero raised to a negative power is undefined.
  • Wired it into Float64/Float64power, decimal array-exponent float fallback, and compute_pow_f64_result.
  • Updated math.slt expectations for pow(0, -0.5) and added coverage for power(0.0::float8, -1.0::float8).
  • Added unit tests in power.rs.

Are these changes tested?

Yes. Unit tests in datafusion/functions/src/math/power.rs, and SQL logic tests in datafusion/sqllogictest/test_files/math.slt (including the regression for #22272).

Are there any user-facing changes?

Yes. Queries that previously returned positive infinity for power / pow with a zero base and negative exponent now return a runtime error (compute error) with that message, matching PostgreSQL for this case.

No public Rust API signature changes; treat as SQL/runtime behavior only unless your process labels SQL semantics as API.

@github-actionsgithub-actionsBot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels May 16, 2026
@raushanprabhakar1

Copy link
Copy Markdown
ContributorAuthor

Hi @Dandandan , requesting you to review. Thanks.

Comment threaddatafusion/sqllogictest/test_files/math.slt
Comment threaddatafusion/functions/src/math/power.rs
@raushanprabhakar1

Copy link
Copy Markdown
ContributorAuthor

Hi @kumarUjjawal, Thanks for the review, extended tests as per your suggestions. Thanks

@kumarUjjawal

kumarUjjawal commented May 18, 2026

Copy link
Copy Markdown
Contributor

Thanks @raushanprabhakar1 looks good, just one request, please don't resolve the comments yourself, I like to read through them while reviewing the newer changes.

@kumarUjjawalkumarUjjawal 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.

There are some discussion going on about which engine we should follow for compatibility, I think this case is pretty straightforward.

@Dandandan
Dandandan added this pull request to the merge queueMay 19, 2026
Merged via the queue into apache:main with commit 82a7d4aMay 19, 2026
35 checks passed
@Jefffrey

Copy link
Copy Markdown
Contributor

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

Labels

functionsChanges to functions implementationsqllogictestSQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PostgreSQL compatibility: power(0.0::float8, -1.0::float8) should error, not return infinity

4 participants

@raushanprabhakar1@kumarUjjawal@Jefffrey@Dandandan