Skip to content

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

Open
alex-fedotyev wants to merge 2 commits into
mainfrom
alex/HDX-1879-pattern-alias-with
Open

fix(search): keep select-alias filters working in Event Patterns#2487
alex-fedotyev wants to merge 2 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.

alex-fedotyev and others added 2 commits June 17, 2026 23:18
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>
@changeset-bot

changeset-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3d51707

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 17, 2026 11:32pm
hyperdx-storybook Ready Ready Preview, Comment Jun 17, 2026 11:32pm

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

Greptile Summary

This PR fixes a bug where filtering Event Patterns on a column exposed only via a source-level alias (e.g. ServiceName as service) produced a ClickHouse Unknown identifier error because the pattern query rebuilds the SELECT without carrying the alias WITH clauses. The fix threads aliasWith into the PatternTable config exactly as it is already done for the histogram and heatmap configs.

  • One-line fix in DBSearchPage.tsx: adds with: aliasWith to the PatternTable config, completing the set of alias-aware configs on the search page.
  • Regression tests in renderChartConfig.test.ts: two new tests confirm the alias (ServiceName) AS service appears in the rebuilt pattern query when the alias map is threaded, and is absent when it is not (proving the pre-fix behaviour).
  • Comment style cleanup: four em-dashes in existing test comments are replaced with commas/semicolons to match repo style.

Confidence Score: 4/5

Safe to merge; the change is a single-field addition that mirrors a pattern already applied to three other configs on the same page.

The core change is minimal and well-tested. The only nearby gap is SearchNumRows in the same pattern-view branch, which would silently show no scanned-row count when a filter references a column alias — a cosmetic silent failure rather than a data error.

The SearchNumRows usage at line 2163 of DBSearchPage.tsx does not receive with: aliasWith and sits in the same pattern-view branch as the fixed PatternTable.

Important Files Changed

Filename Overview
packages/app/src/DBSearchPage.tsx Adds with: aliasWith to the PatternTable config, mirroring the same field already present on histogram and heatmap; SearchNumRows in the same block is left without it.
packages/common-utils/src/tests/renderChartConfig.test.ts Adds two focused regression tests for HDX-1879 confirming WITH-clause presence/absence, plus minor comment style cleanups (em-dashes replaced with commas/semicolons).
.changeset/pattern-table-alias-with.md New patch-level changeset entry for @hyperdx/app describing the fix accurately.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[DBSearchPage\naliasWith from aliasMapToWithClauses] --> B[histogramTimeChartConfig\nwith: aliasWith ✅]
    A --> C[heatmap chartConfig\nwith: aliasWith ✅]
    A --> D[results dbSqlRowTableConfig\nwith: aliasWith ✅]
    A --> E[PatternTable config\nwith: aliasWith ✅ FIXED]
    A --> F[SearchNumRows config\nwith: aliasWith ❌ still missing]

    E --> G[useGroupedPatterns\nusePatterns]
    G --> H[configWithPrimaryAndPartitionKey\nspreads config incl. with]
    H --> I[renderChartConfig\ngenerates WITH clause\nServiceName AS service]
    I --> J[ClickHouse query\nfilter 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\naliasWith from aliasMapToWithClauses] --> B[histogramTimeChartConfig\nwith: aliasWith ✅]
    A --> C[heatmap chartConfig\nwith: aliasWith ✅]
    A --> D[results dbSqlRowTableConfig\nwith: aliasWith ✅]
    A --> E[PatternTable config\nwith: aliasWith ✅ FIXED]
    A --> F[SearchNumRows config\nwith: aliasWith ❌ still missing]

    E --> G[useGroupedPatterns\nusePatterns]
    G --> H[configWithPrimaryAndPartitionKey\nspreads config incl. with]
    H --> I[renderChartConfig\ngenerates WITH clause\nServiceName AS service]
    I --> J[ClickHouse query\nfilter resolves ✅]
Loading

Comments Outside Diff (1)

  1. packages/app/src/DBSearchPage.tsx, line 2163-2169 (link)

    P2 SearchNumRows also missing aliasWith in the pattern view

    SearchNumRows is rendered in the same analysisMode === 'pattern' branch and calls useExplainQuery with the bare chartConfig. When the active filter references a column alias (e.g. service = 'api'), the EXPLAIN query will hit the same Unknown identifier error that PatternTable was just fixed for, silently showing nothing instead of the scanned-row count. Adding with: aliasWith here would keep it consistent with the fix applied one block below.

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

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

Reviews (1): Last reviewed commit: "chore: remove stray em-dashes from rende..." | Re-trigger Greptile

@github-actions

Copy link
Copy Markdown
Contributor

E2E Test Results

All tests passed • 199 passed • 3 skipped • 1389s

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

Tests ran across 4 shards in parallel.

View full report →

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.

1 participant