Repository navigation
Commit 24699cd
authored
fix: Infer singular quantileXxxMerge() from MV quantilesXxxState() (#2154)
## 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:
<img width="1021" height="554" alt="Screenshot 2026-04-23 at 7 47 59 AM" src="https://github.com/user-attachments/assets/4cb325a9-be69-404b-8975-4d2066aee6c1" />
After:
<img width="1023" height="740" alt="Screenshot 2026-04-23 at 7 47 33 AM" src="https://github.com/user-attachments/assets/ca7ca7a0-d0be-4857-9f6c-fba1c25bd2c9" />
### 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:
```sql
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
- Linear Issue: Closes HDX-4099 Closes #2153
- Related PRs:1 parent ef571cc commit 24699cd
3 files changed
Lines changed: 118 additions & 2 deletions
File tree
- .changeset
- packages/common-utils/src
- clickhouse/__tests__
- core
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
290 | 396 | | |
291 | 397 | | |
292 | 398 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
71 | 75 | | |
72 | | - | |
| 76 | + | |
73 | 77 | | |
74 | 78 | | |
75 | 79 | | |
| |||
0 commit comments