Skip to content

fix cast issues - #2474

Merged
knudtty merged 1 commit into
mainfrom
aaron/fix-cast-issue
Jun 16, 2026
Merged

knudtty merged 1 commit into
mainfrom
aaron/fix-cast-issue

Conversation

@knudtty

@knudtty knudtty commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes cast issue reported in #2163

References

Closes #2163

@vercel

vercel Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
hyperdx-oss Ready Ready Preview, Comment Jun 16, 2026 7:10pm
hyperdx-storybook Ready Ready Preview, Comment Jun 16, 2026 7:10pm

Request Review

@changeset-bot

changeset-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 800a572

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/api Patch
@hyperdx/app 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

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: 17 (+ 214 in test files, excluded from tier calculation)
  • Branch: aaron/fix-cast-issue
  • Author: knudtty

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

@greptile-apps

greptile-apps Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a ClickHouse CAST issue (#2163) where parametric aggregate functions (groupUniqArray(N) / groupUniqArrayArray(N)) were receiving query parameters that the ClickHouse distributed query planner wrapped in a _CAST call, causing a type error. The fix introduces inlineNonNegativeInt() — a small guard that validates the argument is a safe non-negative integer and returns its decimal string — then injects it via the existing UNSAFE_RAW_SQL escape hatch so the integer appears as a literal in the final SQL.

  • Core change (metadata.ts): Two ${{ Int32: N }} interpolations inside parametric aggregate functions are replaced with ${{ UNSAFE_RAW_SQL: inlineNonNegativeInt(N, 'label') }}, and a secondary ORDER BY priority for ResourceAttributes is added to getAllFieldsAndValues.
  • Tests (metadata.test.ts): New suite verifies the literal appears in the emitted SQL, no param placeholder is present, and 8 bad-value inputs (null, string, NaN, object, boolean, negative, float, Infinity) are rejected before any ClickHouse query fires.

Confidence Score: 4/5

Safe to merge — the CAST fix is narrowly scoped, the UNSAFE_RAW_SQL escape hatch is gated behind a whitelist-style validator, and the test suite is thorough.

The core fix is correct and well-tested. The only concern is the unexplained ORDER BY addition for ResourceAttributes in getAllFieldsAndValues, which changes result ordering for all callers without any discussion in the PR description.

The ORDER BY change in packages/common-utils/src/core/metadata.ts (line 1607) deserves a quick explanation from the author.

Important Files Changed

Filename Overview
packages/common-utils/src/core/metadata.ts Adds inlineNonNegativeInt() helper and uses UNSAFE_RAW_SQL to inline validated integers into parametric aggregate calls; also adds a secondary ORDER BY priority for ResourceAttributes in getAllFieldsAndValues.
packages/common-utils/src/tests/metadata.test.ts Comprehensive new test suite covering happy paths, 8 bad-value inputs, and the boundary case of 0 for both getAllFieldsAndValues and getMapKeys.
.changeset/fix-parametric-aggregate-cast-distributed.md Changeset marking patch releases for common-utils, api, and app packages.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Caller
    participant Metadata
    participant inlineNonNegativeInt
    participant chSql
    participant ClickHouse

    Caller->>Metadata: "getAllFieldsAndValues({ maxValuesPerKey })"
    Metadata->>inlineNonNegativeInt: validate(maxValuesPerKey, 'maxValuesPerKey')
    alt invalid (non-int, negative, NaN, etc.)
        inlineNonNegativeInt-->>Caller: throws Error (no query fired)
    else "valid integer >= 0"
        inlineNonNegativeInt-->>chSql: returns "20" (decimal string)
        chSql-->>Metadata: SQL with literal groupUniqArray(20)(Value)
        Metadata->>ClickHouse: query with inlined literal (no CAST wrapper)
        ClickHouse-->>Caller: results
    end
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Caller
    participant Metadata
    participant inlineNonNegativeInt
    participant chSql
    participant ClickHouse

    Caller->>Metadata: "getAllFieldsAndValues({ maxValuesPerKey })"
    Metadata->>inlineNonNegativeInt: validate(maxValuesPerKey, 'maxValuesPerKey')
    alt invalid (non-int, negative, NaN, etc.)
        inlineNonNegativeInt-->>Caller: throws Error (no query fired)
    else "valid integer >= 0"
        inlineNonNegativeInt-->>chSql: returns "20" (decimal string)
        chSql-->>Metadata: SQL with literal groupUniqArray(20)(Value)
        Metadata->>ClickHouse: query with inlined literal (no CAST wrapper)
        ClickHouse-->>Caller: results
    end
Loading

Fix All in Claude Code Fix All in Conductor Fix All in Cursor Fix All in Codex

Reviews (1): Last reviewed commit: "fix cast issues" | Re-trigger Greptile

@github-actions

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 198 passed • 3 skipped • 1342s

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

Tests ran across 4 shards in parallel.

View full report →

AND ${timeFilter}
GROUP BY ColumnIdentifier, Key
ORDER BY ColumnIdentifier = 'NativeColumn' DESC, ColumnIdentifier, Key
ORDER BY ColumnIdentifier = 'NativeColumn' DESC, ColumnIdentifier = 'ResourceAttributes' DESC, ColumnIdentifier, Key

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change just to surface ResourceAttributes before other columns before hitting the limit?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's not super related to the other changes here but one I keep noticing

@knudtty
knudtty merged commit 8261b46 into main Jun 16, 2026
26 checks passed

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — 800a5723 Deployed Jun 16, 2026 by vercel[bot]
Preview – hyperdx-storybook — 800a5723 Deployed Jun 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LogAttribute parameters autocomplete is not working

2 participants