Repository navigation
Commit 82a7d4a
fixing negative power to zero (apache#22277)
## Which issue does this PR close?
- Closes apache#22272
## 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`/`Float64` `power`, 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 apache#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.
---------
Co-authored-by: Raushan Prabhakar <[email protected]>1 parent f962686 commit 82a7d4a
2 files changed
Lines changed: 56 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
41 | 52 | | |
42 | 53 | | |
43 | 54 | | |
| |||
203 | 214 | | |
204 | 215 | | |
205 | 216 | | |
206 | | - | |
| 217 | + | |
207 | 218 | | |
208 | 219 | | |
209 | 220 | | |
| |||
382 | 393 | | |
383 | 394 | | |
384 | 395 | | |
385 | | - | |
| 396 | + | |
386 | 397 | | |
387 | 398 | | |
388 | 399 | | |
| |||
436 | 447 | | |
437 | 448 | | |
438 | 449 | | |
439 | | - | |
| 450 | + | |
440 | 451 | | |
441 | 452 | | |
442 | 453 | | |
| |||
657 | 668 | | |
658 | 669 | | |
659 | 670 | | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
660 | 691 | | |
661 | 692 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
742 | 742 | | |
743 | 743 | | |
744 | 744 | | |
745 | | - | |
746 | | - | |
| 745 | + | |
| 746 | + | |
747 | 747 | | |
748 | | - | |
749 | | - | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
750 | 768 | | |
751 | 769 | | |
752 | 770 | | |
| |||
0 commit comments