fixing negative power to zero#22277
Open
raushanprabhakar1 wants to merge 1 commit into
Open
Conversation
Contributor
Author
|
Hi @Dandandan , requesting you to review. Thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
power(0.0::float8, -1.0::float8)should error, not return infinity #22272Rationale for this change
PostgreSQL rejects
power(0::float8, negative::float8)because zero raised to a negative power is undefined. DataFusion usedf64::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?
float64_power_checkedto error whenbase == 0.0andexp < 0.0with messagezero raised to a negative power is undefined.Float64/Float64power, decimal array-exponent float fallback, andcompute_pow_f64_result.math.sltexpectations forpow(0, -0.5)and added coverage forpower(0.0::float8, -1.0::float8).power.rs.Are these changes tested?
Yes. Unit tests in
datafusion/functions/src/math/power.rs, and SQL logic tests indatafusion/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/powwith 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.