Skip to content

fix(search): keep select-alias filters working in Event Patterns - #2487

Merged
kodiakhq[bot] merged 3 commits into
mainfrom
alex/HDX-1879-pattern-alias-with
Jun 25, 2026
Merged

fix(search): keep select-alias filters working in Event Patterns#2487
kodiakhq[bot] merged 3 commits into
mainfrom
alex/HDX-1879-pattern-alias-with

Conversation

@alex-fedotyev

@alex-fedotyev alex-fedotyev commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Filtering Event Patterns on a column the source exposes only under an alias (for example a default select of ServiceName as service) failed with Unknown expression or table expression identifier 'service'. The results table works because its own SELECT defines the alias, but Event Patterns rebuilds the SELECT (sampled body and timestamp, ORDER BY rand() LIMIT) and did not carry the alias definitions, so the filter referenced a column that did not exist in the rebuilt query.

Summary

The PatternTable config now receives the same alias WITH clauses (aliasWith) already threaded into the results, histogram, and heatmap configs in DBSearchPage. usePatterns spreads the config into the sampled query, so the rebuilt pattern query defines the alias in a WITH clause and the filter resolves.

This is the one-field change at the PatternTable call site plus a regression test. It reuses the existing useAliasMapFromChartConfig -> aliasMapToWithClauses -> with mechanism, no new code paths.

image

Why this was invisible to the results table

The results table renders the source's own SELECT, which defines service. ClickHouse resolves a WITH (ServiceName) AS service expression alias inside WHERE, so the filter works there. Event Patterns, histogram, and heatmap all rebuild the SELECT; the other two already passed aliasWith, Event Patterns was the one that did not.

Test plan

  • make ci-lint (eslint + tsc) on @hyperdx/app and @hyperdx/common-utils
  • make ci-unit
  • new renderChartConfig tests: a pattern-shaped config (rebuilt select, ORDER BY rand(), filter on service) renders (ServiceName) AS service in WITH and references it in the predicate; the same config without a threaded alias map omits the definition (the bug). The negative case fails before this change.
  • verified against a live ClickHouse (dev stack) that the rebuilt pattern shape fails with UNKNOWN_IDENTIFIER for an undefined service and succeeds once the (ServiceName) AS service WITH clause is present. Single-node CI with snapshot SQL tests cannot see this class, so I checked it against a running server directly.

The diff also drops 4 stray em-dashes from comments in renderChartConfig.test.ts (repo style; the file was already in the diff).

Companion to #2486, which makes the underlying alias map resilient to ClickHouse-specific SQL the parser rejects. The two touch disjoint files and are independent; this change fixes the common ServiceName as service case on its own.

@changeset-bot

changeset-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 90c8917

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

This PR includes changesets to release 3 packages
Name Type
@hyperdx/app Patch
@hyperdx/api 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

@vercel

vercel Bot commented Jun 17, 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 25, 2026 1:33am
hyperdx-storybook Ready Ready Preview, Comment Jun 25, 2026 1:33am

Request Review

@github-actions github-actions Bot added the review/tier-2 Low risk — AI review + quick human skim label Jun 17, 2026
@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: 6 (+ 64 in test files, excluded from tier calculation)
  • Branch: alex/HDX-1879-pattern-alias-with
  • Author: alex-fedotyev

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 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a regression where filtering Event Patterns on a column exposed only under a source alias (e.g. ServiceName as service) caused a ClickHouse Unknown identifier error. The root cause was that PatternTable rebuilt the SELECT without carrying the aliasWith WITH-clause definitions that the results, histogram, and heatmap configs already received.

  • DBSearchPage.tsx: One-line fix — passes with: aliasWith into the PatternTable config, exactly mirroring the pattern already applied to histogramTimeChartConfig (line 1658) and DBSearchHeatmapChart (line 2253).
  • renderChartConfig.test.ts: Adds two new tests for the HDX-1879 scenario: one positive case confirming the WITH clause is emitted and the filter resolves, one negative case confirming the bug is absent when no alias map is threaded. Also cleans up 4 em-dashes in comments to semicolons/commas.

Confidence Score: 5/5

Safe to merge — the change is a single-field addition that closes the gap between PatternTable and the other two configs already receiving aliasWith.

The fix is minimal and exactly mirrors the pattern already applied to histogramTimeChartConfig and DBSearchHeatmapChart in the same file. Both the positive and negative test cases are present. The only gap (SearchNumRows missing aliasWith in the pattern branch) was already flagged in a prior review comment and is not introduced by this PR.

No files in this diff require special attention. The SearchNumRows gap at line 2191 was pre-existing and is tracked in a previous review comment.

Important Files Changed

Filename Overview
packages/app/src/DBSearchPage.tsx Adds with: aliasWith to the PatternTable config in the pattern analysis branch, making it consistent with the histogram and heatmap configs. The SearchNumRows component in the same branch (line 2191) still lacks this field — already flagged in a previous review comment.
packages/common-utils/src/tests/renderChartConfig.test.ts Adds a well-structured positive/negative test pair for the alias-in-pattern-query fix, plus minor comment punctuation cleanup. Tests correctly assert both the presence of the WITH clause and the filter reference.
.changeset/pattern-table-alias-with.md Correctly scoped changeset entry for the @hyperdx/app patch.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[DBSearchPage: analysisMode === 'pattern'] --> B{aliasWith computed\nfrom aliasMap}
    B --> C[PatternTable config\n...chartConfig\ndateRange: searchedTimeRange\nwith: aliasWith NEW]
    B --> D[histogramTimeChartConfig\nwith: aliasWith existing]
    B --> E[DBSearchHeatmapChart\nwith: aliasWith existing]
    B --> F[SearchNumRows\nno with: aliasWith pre-existing gap]
    C --> G[usePatterns spreads config\ninto sampled query]
    G --> H[ClickHouse query with\nWITH ServiceName AS service\nWHERE service = 'api' resolves]
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"}}}%%
flowchart TD
    A[DBSearchPage: analysisMode === 'pattern'] --> B{aliasWith computed\nfrom aliasMap}
    B --> C[PatternTable config\n...chartConfig\ndateRange: searchedTimeRange\nwith: aliasWith NEW]
    B --> D[histogramTimeChartConfig\nwith: aliasWith existing]
    B --> E[DBSearchHeatmapChart\nwith: aliasWith existing]
    B --> F[SearchNumRows\nno with: aliasWith pre-existing gap]
    C --> G[usePatterns spreads config\ninto sampled query]
    G --> H[ClickHouse query with\nWITH ServiceName AS service\nWHERE service = 'api' resolves]
Loading

Reviews (3): Last reviewed commit: "Merge branch 'main' into alex/HDX-1879-p..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

E2E Test Results

All tests passed • 216 passed • 3 skipped • 1533s

Status Count
✅ Passed 216
❌ Failed 0
⚠️ Flaky 6
⏭️ Skipped 3

Tests ran across 4 shards in parallel.

View full report →

@alex-fedotyev alex-fedotyev self-assigned this Jun 24, 2026
@kodiakhq kodiakhq Bot removed the automerge label Jun 24, 2026
@kodiakhq

kodiakhq Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

This PR currently has a merge conflict. Please resolve this and then re-add the automerge label.

alex-fedotyev and others added 2 commits June 24, 2026 23:48
Filtering on a column the source exposes only under an alias (for
example a default select of `ServiceName as service`) failed in the
Event Patterns view with "Unknown expression or table expression
identifier 'service'". The results table works because its own SELECT
defines the alias, but Event Patterns rebuilds the SELECT and did not
carry the alias definitions.

Thread the source's alias WITH clauses (the same `aliasWith` already
passed to the results, histogram, and heatmap queries) into the
PatternTable config so the rebuilt pattern query defines the alias and
the filter resolves.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@kodiakhq
kodiakhq Bot merged commit 5e3e541 into main Jun 25, 2026
19 checks passed
@kodiakhq
kodiakhq Bot deleted the alex/HDX-1879-pattern-alias-with branch June 25, 2026 01:41
kodiakhq Bot pushed a commit that referenced this pull request Aug 12, 2026
…#2871)

## Why

The PR triage classifier has no critical-path coverage for `packages/common-utils` — the SQL rendering + execution engine that every chart, search, and alert query flows through. A substantial change there can silently alter query semantics product-wide, yet #2859 (664 prod lines moving multi-series metric merge computation into ClickHouse) tiered on generic size/cross-layer rules as **Tier 3**.

## What

Adds a fourth critical band, `QUERY_ENGINE_CRITICAL_PATTERNS`:

- `packages/common-utils/src/core/renderChartConfig.*`
- `packages/common-utils/src/core/builderToRawSql.*`
- `packages/common-utils/src/clickhouse/`

using the same total-churn escalation mechanism as the infra band, but with a **150-line bar** (`QUERY_ENGINE_CRITICAL_MIN_LINES`).

### Why 150 and not infra's 30

Calibrated against 20 recent merged PRs touching these files (prod-only churn):

| Bar | PRs that would flip to Tier 4 |
|---|---|
| ≥30 (infra bar) | 10/20 — including routine Tier 2 chart fixes (#2759, #2613, #2422, #2487) |
| ≥150 | Only engine-level rewrites: #2246 (Increase aggFn), #2634 (builder→raw SQL), #2859 |

These files are among the hottest in the repo — routine chart fixes graze them weekly — so the bar is set high enough that only changes warranting a domain expert escalate.

### Also

- Fixed a stale test fixture path (`src/renderChartConfig.ts` → `src/core/renderChartConfig.ts`; the file moved after the test was written)
- Updated Tier 4 description text and comment triggers/context lines

## Verification

- `node --test .github/scripts/__tests__/pr-triage-classify.test.js` — 112 tests pass (10 new)
- End-to-end replay of #2859's actual file list now yields Tier 4:

> **Query rendering engine substantially modified** — 664 lines (bar: 150). Every chart, search, and alert query flows through this code

No changeset: CI/internal tooling only.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants