Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quantile_at_value returning incorrect value for tdigest #23677

Open
ericGanbat opened this issue Sep 18, 2024 · 0 comments
Open

quantile_at_value returning incorrect value for tdigest #23677

ericGanbat opened this issue Sep 18, 2024 · 0 comments

Comments

@ericGanbat
Copy link

ericGanbat commented Sep 18, 2024

quantile_at_value returning incorrect value for tdigest, however qdigest returning correct value

50% of value is 1. Tdigest returns quantile 0.75 for 1, and qdigest returns correct 0.5 value

WITH test AS (
    SELECT
        *
    FROM (
        VALUES
            (0.1),(0.2),(0.2),(0.3),(0.4),(0.5),(0.5),(0.5),(0.6),(0.6),
            (1.0),(1.0),(1.0),(1.0),(1.0),(1.0),(1.0),(1.0),(1.0),(1.0)
    ) AS t(val)
)

SELECT
    QUANTILE_AT_VALUE(
        CAST(CAST(TDIGEST_AGG(val) AS VARBINARY) AS TDIGEST(DOUBLE)),
        1.0
    ) AS p100,
    QUANTILE_AT_VALUE(
        CAST(CAST(TDIGEST_AGG(val) AS VARBINARY) AS TDIGEST(DOUBLE)),
        0.9999
    ) AS p9999,
        QUANTILE_AT_VALUE(
        CAST(CAST(qdigest_agg(val) AS VARBINARY) AS QDIGEST(DOUBLE)),
        1.0
    ) AS q_digest
FROM test
Screenshot 2024-09-18 at 11 47 43 AM
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

No branches or pull requests

1 participant