Skip to content

Conversation

@tshauck
Copy link
Contributor

@tshauck tshauck commented Dec 5, 2025

Which issue does this PR close?

Rationale for this change

It's possible w/ floating point issues that lo could be greater than hi, causing a panic in clamp.

What changes are included in this PR?

Add a check in clamp that reorders the clamp parameters if they're not in order.

Are these changes tested?

Adds a regression test.

Are there any user-facing changes?

No

@tshauck tshauck changed the title fix: fix panic when lo is greater than high fix: fix panic when lo is greater than hi Dec 5, 2025
@tshauck tshauck force-pushed the fix-panic-in-tdigest branch from 2d85ace to 723e035 Compare December 5, 2025 01:09
@github-actions github-actions bot added the execution Related to the execution crate label Dec 5, 2025

use datafusion_common::instant::Instant;
use object_store::{path::Path, ObjectMeta};
use object_store::{ObjectMeta, path::Path};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated, but was causing the cargo fmt CI job to fail.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 @adriangb seems to have fixed this in the recent commit to main

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me -- thank you @tshauck


use datafusion_common::instant::Instant;
use object_store::{path::Path, ObjectMeta};
use object_store::{ObjectMeta, path::Path};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 @adriangb seems to have fixed this in the recent commit to main

@tshauck tshauck force-pushed the fix-panic-in-tdigest branch from 723e035 to f4b0e2c Compare December 5, 2025 15:31
@github-actions github-actions bot removed the execution Related to the execution crate label Dec 5, 2025
@tshauck tshauck marked this pull request as ready for review December 5, 2025 15:31
}

#[test]
fn test_identical_values_floating_point_precision() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran this test on my (mac) without the code change I verified it fails


thread 'tdigest::tests::test_identical_values_floating_point_precision' (9627513) panicked at /Users/andrewlamb/.rustup/toolchains/1.91.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/num/f64.rs:1413:9:
min > max, or either was NaN. min = 15.699999988079075, max = 15.699999988079073
stack backtrace:

I also double checked the original query it is good now:

DataFusion CLI v51.0.0
> select approx_percentile_cont(0.99) within group (order by value) from (select 15.699999988079073 as value from generate_series(1,215));
+---------------------------------------------------------------------------+
| approx_percentile_cont(Float64(0.99)) WITHIN GROUP [value ASC NULLS LAST] |
+---------------------------------------------------------------------------+
| 15.699999988079075                                                        |
+---------------------------------------------------------------------------+
1 row(s) fetched.
Elapsed 0.035 seconds.

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again @tshauck -- very nice work

@alamb alamb added this pull request to the merge queue Dec 5, 2025
Merged via the queue into apache:main with commit c293854 Dec 5, 2025
27 checks passed
@tshauck tshauck deleted the fix-panic-in-tdigest branch December 5, 2025 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic in approx_percentile_cont

2 participants