`percentile_cont` overflows while interpolating finite Float64 values
- Dominant language
- Rust
- Stars
- 9.3k
- Forks
- 2.4k
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 344
Description
### Describe the bug
I found that `percentile_cont` can return infinity for finite Float64 inputs even when the interpolated result is finite.
### To Reproduce
I reproduced this on 55.1.0 and `main` at `9082d6b10`.
```sql
SELECT percentile_cont(x, CAST(0.5 AS DOUBLE))
FROM (VALUES
(CAST(-1.7976931348623157e308 AS DOUBLE)),
(CAST( 1.7976931348623157e308 AS DOUBLE))
) AS t(x);
```
```text
actual: Infinity
expected: 0.0
### Expected behavior
The median of `-DBL_MAX` and `DBL_MAX` should be `0.0`.
### Additional context
The Float64 interpolation path evaluates [`lower + (upper - lower) * weight`](https://github.com/apache/datafusion/blob/9082d6b10c29b72d56bede3d8e353d9d61fde542/datafusion/functions-aggregate/src/percentile_cont.rs#L943-L945). `upper - lower` overflows before multiplication by `0.5`.
This is separate from #18945: that issue fixed Float16 interpolation by widening it to Float64, while this reproducer overflows in Float64 itself. I couldn't find an existing issue for this behavior.
Contributor guide
Research direction
Start in datafusion/functions-aggregate/src/percentile_cont.rs at the Float64 interpolation expression around lines 943-945, then run the SQL reproduction from the issue. Add regression coverage for finite -DBL_MAX and DBL_MAX inputs, and consider the issue done when their median returns 0.0 rather than Infinity.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100