Skip to content

fix: Infer singular quantileXxxMerge() from MV quantilesXxxState()#2154

Open
pulpdrew wants to merge 1 commit intomainfrom
drew/fix-quantiles-inference
Open

fix: Infer singular quantileXxxMerge() from MV quantilesXxxState()#2154
pulpdrew wants to merge 1 commit intomainfrom
drew/fix-quantiles-inference

Conversation

@pulpdrew
Copy link
Copy Markdown
Contributor

@pulpdrew pulpdrew commented Apr 23, 2026

Summary

This PR fixes a bug in the quantile function inference used for MV queries. For MVs defined with quantilesXxxState() columns, HyperDX will now infer a quantileXxxMerge function instead of a quantilesXxxMerge function. quantilesXxxMerge returns an array result, which is incompatible with HyperDX's chart implementations.

I've tested that quantile, quantileTDigest, and quantileExact all return equivalent results when querying quantileXxxMerge and quantilesXxxMerge from a quantilesXxxState column.

Screenshots or video

Before:

Screenshot 2026-04-23 at 7 47 59 AM

After:

Screenshot 2026-04-23 at 7 47 33 AM

How to test locally or on Vercel

This can be tested locally by creating a MV as follows and registering it in the Traces source configuration:

CREATE TABLE otel_traces_1m_quantiles
(
    `Timestamp` DateTime,
    `ServiceName` LowCardinality(String),
    `StatusCode` LowCardinality(String),
    `count` SimpleAggregateFunction(sum, UInt64),
    `avg__Duration` AggregateFunction(avg, UInt64),
    `max__Duration` SimpleAggregateFunction(max, Int64),
    `quantiles__Duration` AggregateFunction(quantiles(0.5, 0.95), UInt64)
)
ENGINE = AggregatingMergeTree
ORDER BY (Timestamp, ServiceName, StatusCode);

CREATE MATERIALIZED VIEW otel_traces_1m_quantiles_mv TO otel_traces_1m_quantiles
AS
SELECT
    toStartOfMinute(Timestamp) AS Timestamp,
    ServiceName,
    StatusCode,
    count() AS count,
    avgState(Duration) AS avg__Duration,
    maxSimpleState(Duration) AS max__Duration,
    quantilesState(0.5, 0.95)(Duration) AS quantiles__Duration
FROM otel_traces
GROUP BY
    Timestamp,
    ServiceName,
    StatusCode;

References

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 23, 2026

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

Project Deployment Actions Updated (UTC)
hyperdx-oss Ready Ready Preview, Comment Apr 23, 2026 11:46am

Request Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 23, 2026

🦋 Changeset detected

Latest commit: 532258d

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

@github-actions github-actions Bot added the review/tier-2 Low risk — AI review + quick human skim label Apr 23, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🔵 Tier 2 — Low Risk

Small, isolated change with no API route or data model modifications.

Why this tier:

  • Standard feature/fix — introduces new logic or modifies core functionality

Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns.
SLA: Resolve within 4 business hours.

Stats
  • Production files changed: 1
  • Production lines changed: 8 (+ 106 in test files, excluded from tier calculation)
  • Branch: drew/fix-quantiles-inference
  • Author: pulpdrew

To override this classification, remove the review/tier-2 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@github-actions
Copy link
Copy Markdown
Contributor

PR Review

✅ No critical issues found.

The fix is correct and minimal — .replace(/^quantiles/, 'quantile') on the extracted function name properly normalizes all quantilesXxx variants (including quantilesExact, quantilesTDigestExclusive, etc.) to their singular scalar-returning forms. Tests cover the two most common cases (quantiles and quantilesTDigest) with realistic mock setups.

One minor observation (not blocking): the existing test suite apparently already covers quantileExact (referenced in the PR description as "quantile, quantileTDigest, and quantileExact all return equivalent results"), but there's no new test for quantilesExactquantileExactMerge. The regex handles it correctly regardless, so this is just a coverage gap if exhaustive test documentation is desired.

@github-actions
Copy link
Copy Markdown
Contributor

E2E Test Results

All tests passed • 146 passed • 3 skipped • 1148s

Status Count
✅ Passed 146
❌ Failed 0
⚠️ Flaky 5
⏭️ Skipped 3

Tests ran across 4 shards in parallel.

View full report →

@pulpdrew pulpdrew requested review from a team and bot-hyperdx and removed request for a team April 23, 2026 12:02
@pulpdrew pulpdrew changed the title fix: Infer singular quantileXXX() from MV quantilesXXXState() fix: Infer singular quantileXxxMerge() from MV quantilesXXXState() Apr 23, 2026
@pulpdrew pulpdrew changed the title fix: Infer singular quantileXxxMerge() from MV quantilesXXXState() fix: Infer singular quantileXxxMerge() from MV quantilesXxState() Apr 23, 2026
@pulpdrew pulpdrew changed the title fix: Infer singular quantileXxxMerge() from MV quantilesXxState() fix: Infer singular quantileXxxMerge() from MV quantilesXxxState() Apr 23, 2026
@pulpdrew pulpdrew requested review from a team and dhable and removed request for a team and bot-hyperdx April 23, 2026 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge review/tier-2 Low risk — AI review + quick human skim

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Accelerated queries using quantilesState

1 participant