Skip to content

fix(common-utils): inline the KV rollup value limit again - #3859

Open
inexpressive wants to merge 1 commit into
ClickHouse:mainfrom
inexpressive:fix/rollup-values-distributed-cast
Open

inexpressive wants to merge 1 commit into
ClickHouse:mainfrom
inexpressive:fix/rollup-values-distributed-cast

Conversation

@inexpressive

@inexpressive inexpressive commented Nov 30, 2026 •

Copy link
Copy Markdown

Summary

Filter values from the KV rollup MVs fail when the rollup table is Distributed:

Code: 70. DB::Exception: Conversion from AggregateFunction(groupUniqArray(20), LowCardinality(String)) to AggregateFunction(groupUniqArray(20), LowCardinality(String)) is not supported: While executing Remote. (CANNOT_CONVERT_TYPE)

#2474 fixed this for #2163 by inlining the limit as a literal. #2643 rewrote getMetadataMVKeyValues and brought the bound Int32 parameter back. This restores the literal and adds a test that fails on main.

The ClickHouse side is ClickHouse/ClickHouse#71887: a signed parameter of a parametric aggregate (_CAST(20, 'Int32')) breaks the type conversion on the remote. Unsigned types and literals work. Reproduced on 25.8.33 and 26.8.51; 24.3.18 is not affected.

packages/api/src/mcp/tools/sources/describeMetric.ts has the same pattern (groupUniqArray(${{ Int32: MAX_ATTR_VALUES }})). Left out to keep this PR to one code path; happy to add it here or in a follow-up.

Screenshots or video

Traces source on a 2-shard × 2-replica cluster, rollup table Distributed. Taken on 2.46.0 with the same change applied to the built bundle.

Before After
before no SpanName / ServiceName / SpanKind / StatusCode under Filters after all four present

How to reproduce

Starting point: own setup. play.hyperdx.io and local mode use a single node, so they don't show it.

Minimal repro on any cluster with 2+ shards (HTTP interface, param_limit=20):

SELECT groupUniqArray({limit:Int32})(dummy) FROM cluster('<cluster>', system.one); -- Code: 70
SELECT groupUniqArray(20)(dummy) FROM cluster('<cluster>', system.one);            -- [0]

Full setup: ClickHouse 25.8, 2 shards; the seed schema from docker/otel-collector/schema/seed with each table as Replicated* <name>_local plus a Distributed table under the original name; trace source with metadataMaterializedViews.kvRollupTable = otel_traces_kv_rollup_15m.

On main:

  1. Open Search, pick the trace source, set the time range to cover the data.
  2. Under Filters, ServiceName, SpanName, SpanKind and StatusCode are missing; the clickhouse-proxy request for the rollup returns 500 with code 70.

On this branch:

  1. Same steps: the four filters show their values, no 500.

How to test on Vercel preview

N/A — the demo server is a single node.

References


Note

Low Risk
Small, targeted SQL generation change with validation via inlineNonNegativeInt and a regression test; restores prior known-good behavior for Distributed rollup reads.

Overview
Restores literal maxValuesPerKey in the KV rollup MV query (groupUniqArray(7)(Value) instead of a bound {limit:Int32}), matching the pattern already used elsewhere in metadata via inlineNonNegativeInt.

This fixes Search filter values missing (500 / ClickHouse code 70) when kvRollupTable is a Distributed table over multiple shards—a regression from reintroducing the Int32 parameter after #2474.

A unit test asserts the MV path emits groupUniqArray(N)(Value) in SQL and does not use a parameterized aggregate argument.

Reviewed by Cursor Bugbot for commit dfd8b12. Bugbot is set up for automated code reviews on this repo. Configure here.

@inexpressive
inexpressive requested a review from a team as a code owner November 30, 2026 06:14
@vercel

vercel Bot commented Nov 30, 2026

Copy link
Copy Markdown

@inexpressive is attempting to deploy a commit to the HyperDX Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Nov 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: dfd8b12

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

This PR includes changesets to release 1 package
Name Type
@hyperdx/common-utils 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 external needs-vouch Author needs a maintainer to vouch for them labels Nov 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hi @inexpressive, thanks for the pull request!

Before we review code from a first-time contributor, a maintainer vouches for them, and you're not on our list yet. There's nothing else to file and this PR stays open — a maintainer will look at it, usually within a day or two, and vouch for you right here if it's a genuine attempt at the problem.

To make that quick, check the PR description has:

  • The issue it addresses (ideally one labelled Accepting PR) and why the change is needed
  • Steps to reproduce the problem and verify the fix, starting from https://play.hyperdx.io or yarn app:dev:local connected to the demo server
  • Before/after screenshots if anything in the UI changed

More detail in our contributing guide.

@github-actions

Copy link
Copy Markdown
Contributor

PR Review

✅ No issues found.

@github-actions

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found.

The production change is a single line: the KV rollup groupUniqArray(N)(Value) limit now renders through the existing inlineNonNegativeInt helper (packages/common-utils/src/core/metadata.ts:180) instead of a bound Int32 parameter, matching the four sibling parametric-aggregate sites already using that helper. Security confirmed the UNSAFE_RAW_SQL splice is injection-safe by construction (Number.isInteger + >= 0 guard, String() yields digits only), and all current callers pass compile-time constants. Correctness confirmed behavior is identical for valid inputs and that a hypothetical bad input degrades gracefully via the outer .catch(() => undefined). The added regression test meaningfully guards the fix (asserts the inlined-literal shape and rejects the pre-fix bound-param shape).

🟡 P2 -- recommended

  • packages/api/src/mcp/tools/sources/describeMetric.ts:406 -- The sibling groupUniqArray(${{ Int32: MAX_ATTR_VALUES }})(...) carries the identical bound-Int32 pattern that fails over Distributed rollup tables, so that MCP code path still hits the same CANNOT_CONVERT_TYPE error this PR fixes in common-utils; it is pre-existing and left untouched here.
    • Fix: File a follow-up to inline the limit in describeMetric.ts using the same validated-literal approach.
    • testing, maintainability
🔵 P3 nitpicks (1)
  • packages/common-utils/src/core/metadata.ts:2121 -- The new routing of maxValuesPerKey through inlineNonNegativeInt adds a throw-on-bad-input path for this caller that has no negative-path test (positive path is covered; no current caller can trigger the throw).
    • Fix: Add a unit test asserting a non-integer/negative maxValuesPerKey surfaces cleanly (strategy resolves undefined) rather than producing invalid SQL.
    • correctness, testing, security

Reviewers (6): correctness, testing, maintainability, project-standards, security, kieran-typescript.

Testing gaps:

  • The regression test guards the rendered SQL string shape (ClickHouse client is mocked); no integration test executes the rollup query against an actual Distributed table, so a future regression via a different render path would not be caught at the unit level.
  • Previous-comments reviewer was not run: the PR's only prior comments are automated bot messages (Vercel, changeset-bot) with no human feedback to verify.

No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external needs-vouch Author needs a maintainer to vouch for them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant