Skip to content

fix(common-utils): guard metadata rollup queries against invalid date… - #2941

Open
Vansh98789 wants to merge 2 commits into
hyperdxio:mainfrom
Vansh98789:fix/invalid-date-metadata-rollup
Open

fix(common-utils): guard metadata rollup queries against invalid date…#2941
Vansh98789 wants to merge 2 commits into
hyperdxio:mainfrom
Vansh98789:fix/invalid-date-metadata-rollup

Conversation

@Vansh98789

@Vansh98789 Vansh98789 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes BAD_QUERY_PARAMETER (457) failures on metadata key/value rollup queries (e.g. filter dropdowns and field lists).

When a metadata query is built with an invalid date in its date range, Date.getTime() returns NaN. That NaN is serialized as the literal string "nan" and bound to a ClickHouse Int64 parameter, causing the query to fail with:

Code: 457. DB::Exception: Cannot parse 'nan' as Int64

This happens in two places in metadata.ts:

  • getMapKeys — builds rollup queries from getAlignedDateRange(dateRange, granularity) and binds { Int64: date.getTime() }
  • getMetadataMVKeyValues — same pattern for batched key/value lookups

Changes

File Change
common-utils/src/core/utils.ts Added isDateRangeValid(dateRange) — returns false if either bound's getTime() is not a finite number
common-utils/src/core/metadata.ts Added guard in getMapKeys — skips metadata queries and returns [] when the date range is invalid
common-utils/src/core/metadata.ts Added guard in getMetadataMVKeyValues — returns undefined so callers fall through to the raw-table strategy
common-utils/src/core/__tests__/metadata.test.ts Added unit tests for the helper and getMapKeys guard
.changeset/tidy-invalid-dates.md Added patch changeset

Tests

  • isDateRangeValid accepts a valid range
  • isDateRangeValid rejects a range with an invalid start date
  • isDateRangeValid rejects a range with an invalid end date
  • getMapKeys returns [] and never calls ClickHouse when given an invalid range

Test command

cd packages/common-utils
npx jest src/core/__tests__/metadata.test.ts

Screenshots or video

N/A — non-UI change.

How to test on Vercel preview

N/A — non-UI change.

References

@changeset-bot

changeset-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 65102f3

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

@vercel

vercel Bot commented Aug 18, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@greptile-apps

greptile-apps Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR prevents invalid JavaScript dates from being serialized as ClickHouse Int64 metadata-query parameters.

  • Adds a shared finite-timestamp date-range validator.
  • Short-circuits invalid metadata key and rollup key/value queries.
  • Adds focused unit coverage and a patch changeset.

Confidence Score: 5/5

The PR appears safe to merge, with no actionable changed-code failures identified.

The new guards reject non-finite date bounds before the affected metadata rollup queries construct ClickHouse integer parameters, while preserving the established return contracts used by callers.

Important Files Changed

Filename Overview
packages/common-utils/src/core/metadata.ts Adds early validation to avoid executing metadata key and rollup key/value queries with non-finite timestamps; no changed-code defect was identified.
packages/common-utils/src/core/utils.ts Adds a straightforward helper that rejects date bounds whose timestamps are not finite.
packages/common-utils/src/core/tests/metadata.test.ts Covers valid and invalid date ranges and verifies that invalid getMapKeys input does not reach ClickHouse.
.changeset/tidy-invalid-dates.md Correctly records the metadata-query guard as a patch-level common-utils change.

Reviews (1): Last reviewed commit: "Merge branch 'main' into fix/invalid-dat..." | Re-trigger Greptile

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid Date reaches metadata rollup queries as "nan" Int64 param (BAD_QUERY_PARAMETER 457)

1 participant