Skip to content

fix: fix panic when lo is greater than hi - #19099

Merged
alamb merged 1 commit into
apache:mainfrom
tshauck:fix-panic-in-tdigest
Dec 5, 2025
Merged

fix: fix panic when lo is greater than hi#19099
alamb merged 1 commit into
apache:mainfrom
tshauck:fix-panic-in-tdigest

Conversation

@tshauck

Copy link
Copy Markdown
Contributor

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

@tshaucktshauck changed the title fix: fix panic when lo is greater than highfix: fix panic when lo is greater than hiDec 5, 2025
@tshauck
tshauckforce-pushed the fix-panic-in-tdigest branch from 2d85ace to 723e035CompareDecember 5, 2025 01:09
@github-actionsgithub-actionsBot 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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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

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

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
Copy Markdown
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
tshauckforce-pushed the fix-panic-in-tdigest branch from 723e035 to f4b0e2cCompareDecember 5, 2025 15:31
@github-actionsgithub-actionsBot 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
Copy Markdown
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
>selectapprox_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.

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

Thanks again @tshauck -- very nice work

@alamb
alamb added this pull request to the merge queueDec 5, 2025
Merged via the queue into apache:main with commit c293854Dec 5, 2025
27 checks passed
@tshauck
tshauck deleted the fix-panic-in-tdigest branch December 5, 2025 21:40
Sign up for freeto 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

@tshauck@alamb