Skip to content

Fixed td_quantile returning NaN when 1 sample - #33

Open
bjornite wants to merge 1 commit into
RedisBloom:masterfrom
getCUJO:td-quantile-nan-fix
Open

Fixed td_quantile returning NaN when 1 sample#33
bjornite wants to merge 1 commit into
RedisBloom:masterfrom
getCUJO:td-quantile-nan-fix

Conversation

@bjornite

@bjornite bjornite commented Apr 26, 2023

Copy link
Copy Markdown

When the t-digest has only a single sample, td_quantile returns NaN when it should return the value of the single sample.

The problem is that td_compress does not update the merged_nodes counter when there is only a single value.

Fix is to check on (merged_nodes + unmerged_nodes)

Steps to reproduce:

#include <cmocka.h>

td_histogram_t *h = td_new(50.0);
td_add(h, 0.2, 1);
assert_true(td_quantile(h, 0.5) == 0.2);

@filipecosta90
filipecosta90 self-requested a review April 26, 2023 20:46
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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.

1 participant