Skip to content

fix(common-utils): merge DDSketch and GK quantile states with their accuracy - #3737

Draft
alex-fedotyev wants to merge 1 commit into
alex/HDX-6120-trace-rollup-1-demo-mv-configfrom
alex/HDX-6120-trace-rollup-2-dd-merge-params
Draft

alex-fedotyev wants to merge 1 commit into
alex/HDX-6120-trace-rollup-1-demo-mv-configfrom
alex/HDX-6120-trace-rollup-2-dd-merge-params

Conversation

@alex-fedotyev

@alex-fedotyev alex-fedotyev commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A view column built with quantileDDState(0.01, 0.5) or quantileGKState(100, 0.5) keeps the sketch's accuracy in its state, and the merge has to be given the same accuracy. The optimizer rewrote a p95 over such a column as quantileDDMerge(0.95)(col). ClickHouse accepts that, reads 0.95 as the accuracy, uses the default level, and returns an unrelated number without an error: 2,966 over numbers(100000), where the p95 is 95,000. GK rejects the call (quantileGK requires accuracy parameter with integer type), so the EXPLAIN check failed and GK views were never used. Alerts go through the same optimizer.

The optimizer now reads the accuracy from the column's type and keeps it on the rewritten select item, and the renderer emits quantileDDMerge(0.01, 0.95)(col), which returns 95,830 on the same data (within the sketch's 1%). Singular and plural states (quantilesDD(0.01, 0.9, 0.99)) both work. The accuracy only exists on the optimized config built at query time, so the saved chart schema and the external API don't change. Sketches whose only parameter is the level (t-digest, reservoir, BFloat16, exact) render as before, and no snapshot changes.

No demo or built-in view stores DDSketch or GK states (the demo rollup uses t-digest), so the demo data shows no difference.

Stack

Second of three PRs in a GitHub stack (stack #3778). The header says this PR merges into the branch below it, but the stack's base is main: merging a PR lands it and every PR below it on main, one squashed commit each. Each diff is only its own change, and CI runs as if each PR targets main.

  1. fix(app): match the demo traces rollup's dimension columns to its table #3736 Demo traces rollup lists its real dimension columns
  2. fix(common-utils): merge DDSketch and GK quantile states with their accuracy #3737 DDSketch and GK quantile states merge with their accuracy (this PR)
  3. feat(app): show materialized view indicators on the trace search RED charts #3739 Materialized view indicators on the trace search RED charts

The three changes don't depend on each other's code. They're groundwork for a default trace rollup, ordered smallest first.

How to reproduce

Starting point: any ClickHouse (clickhouse local works), and a checkout of this branch with Docker for the integration test.

On main:

  1. Compare the merge the optimizer emitted with the one it emits now:
    SELECT
        quantileDDMerge(0.95)(s) AS level_only,
        quantileDDMerge(0.01, 0.95)(s) AS with_accuracy
    FROM (SELECT quantileDDState(0.01, 0.5)(number) AS s FROM numbers(100000))
    level_only is 2,966 and with_accuracy is 95,830. The exact p95 is 95,000.
  2. Restore the two changed source files from main and run the new integration test. The DDSketch and GK cases fail:
    git checkout origin/main -- packages/common-utils/src/core/materializedViews.ts packages/common-utils/src/core/renderChartConfig.ts
    make dev-int-common-utils FILE=materializedViewQuantileSketches

On this branch:

  1. make dev-int-common-utils FILE=materializedViewQuantileSketches: the test builds one-minute rollups with quantileDD, quantileGK, quantileTDigest and quantileBFloat16 states over 100,000 spans, reads p95 and p99 through the optimizer at five-minute buckets, and all four come within their error bound of quantileExact on the raw table.

How to test on Vercel preview

N/A, non-UI change: no demo view stores DDSketch or GK states.

References

@changeset-bot

changeset-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 13ef89a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@hyperdx/common-utils Patch
@hyperdx/app Patch
@hyperdx/api Patch
@hyperdx/otel-collector Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Nov 24, 2026 2:11am UTC
hyperdx-storybook Ready Ready Preview Nov 24, 2026 2:11am UTC

Request Review

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 107 in total (1.12%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 474 passed • 1 skipped • 1084s

Status Count
✅ Passed 474
❌ Failed 0
⚠️ Flaky 11
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

…ccuracy

A materialized view column built with quantileDD(accuracy, level) or
quantileGK(accuracy, level) was merged as quantileDDMerge(level), which
ClickHouse reads as an accuracy, so p95 came back as a different quantile with
no error. GK merges failed the EXPLAIN check, so those views were skipped.

The optimizer now reads the sketch's accuracy from the column type and keeps it
on the rewritten select item, and the renderer emits quantileDDMerge(0.01, 0.95).
The saved select schema doesn't change. Sketches whose state doesn't depend on
the level (t-digest, reservoir, BFloat16, exact) render as before.

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — 13ef89a0 Deployed Nov 24, 2026 by vercel[bot]
Preview – hyperdx-storybook — 13ef89a0 Deployed Nov 24, 2026 by vercel[bot]
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