fix(common-utils): wrap Date partition columns in toDate() inside CTE-using queries (HDX-4247)#2291
fix(common-utils): wrap Date partition columns in toDate() inside CTE-using queries (HDX-4247)#2291dhable wants to merge 4 commits into
Conversation
…-using queries (HDX-4247) When a chart config injects a subquery CTE (e.g. for pattern sampling) into the outer query against a base table whose partition key includes a Date column, the column-metadata lookup was skipped wholesale, leaving the time filter without the required toDate() wrapper on the RHS. ClickHouse then promotes Date -> DateTime at midnight, excluding the entire day's rows for any window that doesn't include midnight UTC. Pair the CTE skip with !databaseName (matching the established guard pattern at renderChartConfig.ts:524 and :842), and tie the warning to a single computed skipColumnLookup boolean so the two conditions cannot desync. Fixes Event Patterns 'No results found', and silently improves heatmap, value-distribution autocomplete, and services dashboard on Date-PK sources.
🦋 Changeset detectedLatest commit: 9c08e7f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🔵 Tier 2 — Low RiskSmall, isolated change with no API route or data model modifications. Why this tier:
Additional context: agent branch ( Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns. Stats
|
|
<!-- claude-code-review --> PR Review✅ No critical issues found. Targeted, well-scoped fix for HDX-4247. The skip condition is correctly tightened from Minor observations (non-blocking):
Changeset entry, scope ( |
E2E Test Results✅ All tests passed • 177 passed • 3 skipped • 1270s
Tests ran across 4 shards in parallel. |
Deep Review✅ No critical issues found. The narrowing of the skip condition is correct, the precedent at 🟡 P2 — recommended
🔵 P3 nitpicks (3)
Reviewers (6): ce-correctness-reviewer, ce-testing-reviewer, ce-maintainability-reviewer, ce-kieran-typescript-reviewer, ce-adversarial-reviewer, ce-project-standards-reviewer. Testing gaps:
|
|
<!-- claude-code-review --> PR Review✅ No critical issues found. Targeted, minimal fix with a regression test that fails on Minor (non-blocking) nit:
|
PR Review✅ No critical issues found. Targeted, well-scoped fix. The new Minor notes (non-blocking):
|
Summary
Event Patterns (and several other CTE-using panels) silently return No results found against any source whose partition/primary key is a
Datecolumn, when the query window does not cross midnight UTC. This happens for the entire class of sources that follow the OpenTelemetry ClickHouse exporter default of partitioning byevent_date/EventDate.Root cause
In
timeFilterExpr, the column-metadata lookup is skipped whenever the chart config contains a subquery CTE:The skip is too aggressive. A subquery CTE in
WITHdoes not imply thatFROMreferences the CTE — chart configs routinely inject a subquery CTE (e.g. pattern sampling) while the outerFROMstill hits a real base table. When that base-table column isDate-typed, the lookup is the only signal that tells the filter to wrap bounds intoDate(...). Without it, ClickHouse promotesDate -> DateTimeat midnight and any window not crossing midnight UTC returns zero rows.Fix
Tighten the skip to
(hasSubqueryCte(withClauses) && !databaseName), matching the established guard pattern already used twice in the same file (line 524 and line 842) —databaseNameis the existing signal thatFROMis a CTE alias rather than a real table. Also consolidate the lookup-skip and warning-suppression into oneskipColumnLookupboolean so they cannot desync.Behavioral diff:
withClausesdatabaseNameImpact
timeFilterExprwith a subquery CTE against a base table — heatmap tile, value-distribution autocomplete, services dashboard.DateTime/DateTime64.Test
Added a regression test inside
describe('timeFilterExpr', …)that pins the fix:timestampValueExpression: 'date'(mocked asDate-typed)databaseName: 'default',tableName: 'target_table'(real base table)with: [{ name: 'tableStats', sql: ... }]toDate(fromUnixTimestamp64Milli(...)).The test fails on
mainand passes with this change.Screenshots or video
N/A — non-UI change in
@hyperdx/common-utils. The user-visible effect (Event Patterns rendering rows instead of "No results found") is downstream of this SQL generation.How to test on Vercel preview
N/A — non-UI change. To exercise manually:
Datecolumn (e.g. an OTel ClickHouse exporter table withevent_date Date).References
packages/common-utils/src/core/renderChartConfig.ts:524,:842