Skip to content

feat: show generated SQL in the SQL query filter preview - #3823

Merged
kodiakhq[bot] merged 2 commits into
mainfrom
sql-filter-preview
Nov 25, 2026
Merged

kodiakhq[bot] merged 2 commits into
mainfrom
sql-filter-preview

Conversation

@karl-power

@karl-power karl-power commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Shows the SQL a SQL query filter runs, with its variables and macros filled in, below Preview values in the filter editor. This matches the raw SQL tile's Generated SQL, so users can see what $svc, $__filter(...), $__timeFilter(...), $__sourceTable and $__filters turned into.

  • renderSqlQueryFilterValuesQuery also returns expandedSql: the filter's SQL after expansion, without the SELECT DISTINCT … LIMIT wrapper the values query adds.
  • useSqlQueryFilterValues moves its per-filter setup and its $__filters step into helpers, with no behavior change. The new useSqlQueryFilterGeneratedSql uses the same helpers, so the SQL shown is built by the code that runs the values query. It sends nothing to ClickHouse.
  • After Preview values, the editor shows a collapsed Generated SQL section, including when the query fails. As on the raw SQL tile, the time range is written in as millisecond timestamps and the SQL is formatted.
  • QueryPreviewAccordion takes an optional variant. The filter editor passes noPadding, so the section lines up with the other form fields.

Screenshots or video

Screenshot 2026-11-25 at 10 32 34 Screenshot 2026-11-25 at 10 33 05

How to reproduce

Starting point: yarn app:dev:local connected to the demo server (onboarding → "Connect to Demo Server"), or the Vercel preview.

On main:

  1. Open a dashboard, click Edit filters and variables, then Add new filter.
  2. Create a Static values filter named Service with options frontend and checkout, and variable name svc. Save it.
  3. Add a SQL query values filter named Severity on connection Demo and source Logs, with:
    SELECT SeverityText
    FROM $__sourceTable
    WHERE $__timeFilter(Timestamp)
      AND $__filter(ServiceName, $svc)
      AND $__filters
    GROUP BY SeverityText
    ORDER BY count() DESC
  4. Click Preview values. Only the values are listed. There's no way to see what the macros and $svc expanded to.

On this branch:

  1. Repeat the steps above, then expand Generated SQL below the values.
  2. It shows the Logs table in place of $__sourceTable and timestamps in place of $__timeFilter. $__filter(ServiceName, $svc) shows as (1=1 /** no values selected for variable 'svc' */).
  3. Save the filter, close the modal, and pick frontend in Service.
  4. Edit Severity and click Preview values again. Generated SQL now shows (ServiceName IN ('frontend')), and the values narrow to match.

References

  • Linear: HDX-6191

@karl-power
karl-power requested a review from a team as a code owner November 25, 2026 09:37
@vercel

vercel Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Nov 25, 2026 11:27am UTC
hyperdx-storybook Ready Ready Preview Nov 25, 2026 11:27am UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1a2e248

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

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

@github-actions github-actions Bot added the review/tier-3 Standard — full human review required label Nov 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🟡 Tier 3 — Standard

Introduces new logic, modifies core functionality, or touches areas with non-trivial risk.

Why this tier:

  • Diff size: 413 production lines changed (Tier 2 max: < 250)
  • Cross-layer change: touches frontend (packages/app) + shared utils (packages/common-utils)

Review process: Full human review — logic, architecture, edge cases.
SLA: First-pass feedback within 1 business day.

Stats
  • Production files changed: 6
  • Production lines changed: 413 (+ 225 in test files, excluded from tier calculation)
  • Branch: sql-filter-preview
  • Author: karl-power

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

@github-actions

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 107 in total (1.12%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

After Preview values, the SQL query filter editor shows the filter's SQL
with variables and macros filled in, in a collapsed Generated SQL section
like the raw SQL tile's. It's built by the same helpers the values query
uses, and shows even when the query fails.

- renderSqlQueryFilterValuesQuery also returns expandedSql, without the
  values wrapper
- Move useSqlQueryFilterValues' per-filter setup and $__filters step into
  helpers shared with the new useSqlQueryFilterGeneratedSql
- QueryPreviewAccordion takes an optional variant
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 474 passed • 1 skipped • 1115s

Status Count
✅ Passed 474
❌ Failed 0
⚠️ Flaky 14
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

@github-actions

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 P0/P1 in code this PR adds or changes: fix before asking for review.
  • 🟡 P2 in code this PR changes: your call. Fix if small, otherwise reply.
  • 🔵 P3 is collapsed at the bottom: nobody needs to act on it before merge.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    priority. Reply with one sentence; if it is P0, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

1 finding(s): 🔴 0 P0/P1 · 🟡 1 P2 · 🔵 0 P3

None could be anchored to changed lines; they are listed below.

Findings outside the changed lines

  • 🟡 P2 packages/app/src/components/DashboardFiltersModal/SqlQueryFilterGeneratedSql.tsx:203 — Generated SQL section unmounts and re-collapses each time the previewed SQL or date range changes → The SQL is rendered asynchronously (queryFn), and the query has no placeholderData. So when the user edits the SQL and clicks Preview values again, or the date range changes, the key changes and data is briefly undefined. This component then returns null, and the QueryPreviewAccordion unmounts. That accordion is uncontrolled (defaultValue="" in QueryPreviewAccordion.tsx), so it remounts collapsed. A user who opened Generated SQL to check their changes has to expand it again after every re-run. Fix: pass placeholderData: keepPreviousData in useSqlQueryFilterGeneratedSql, as useSqlQueryFilterValues already does. Or hide only the SQLPreview body and keep the accordion mounted, or lift its open state into the form.

Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides.

@github-actions

Copy link
Copy Markdown
Contributor

Deep Review

Multi-agent review of the SQL query filter "Generated SQL" preview. Scope: git diff f36e6788f (12 files, ~413 production lines) — a new useSqlQueryFilterGeneratedSql hook, a behavior-preserving refactor of useSqlQueryFilterValues into shared helpers, a new SqlQueryFilterGeneratedSql component, and an additive expandedSql field on the exported renderSqlQueryFilterValuesQuery.

✅ No critical issues found. The useSqlQueryFilterValues refactor preserves behavior (the call.params → renderValuesCall params switch is provably equivalent), the added expandedSql return field is structurally additive for all in-repo callers, the generated-SQL display is read-only and carries only numeric time params (no new injection/XSS surface), and prior PR comments are bot-only with nothing to address.

🟡 P2 — recommended

  • packages/app/src/hooks/useSqlQueryFilterGeneratedSql.ts:58 — The generated-SQL query omits placeholderData: keepPreviousData (unlike the sibling values hook) and the component returns null while sql == null, so on every re-preview or variable/time-range change the query key changes, data reverts to undefined, and the uncontrolled QueryPreviewAccordion (defaultValue="") unmounts and remounts collapsed — losing the user's expanded view and flashing empty; the same null branch also makes the section silently vanish on the hook's own render error.
    • Fix: Add placeholderData: keepPreviousData to the useQuery call so the previous SQL persists across key changes, and render an explicit loading/error state in SqlQueryFilterGeneratedSql instead of collapsing to null.
    • adversarial, julik-frontend-races
🔵 P3 nitpicks (1)
  • packages/app/src/hooks/useSqlQueryFilterGeneratedSql.ts:42 — The hook's "runs nothing on ClickHouse / sends nothing to ClickHouse" doc is inaccurate: when the template uses $__filters with an active source and broadcast selections, renderValuesCall → renderSourceFiltersToSql issues a metadata (system.columns/DESCRIBE) query, and the unit test upholds the invariant only because it mocks renderSourceFiltersToSql.
    • Fix: Soften the docstring to state it runs no values query (metadata may be fetched, shared and cached with the values preview), and add a test exercising the real broadcast path.
    • correctness, adversarial

Reviewers (12): correctness, adversarial, security, testing, maintainability, project-standards, api-contract, kieran-typescript, julik-frontend-races, previous-comments, agent-native, learnings-researcher.

Testing gaps:

  • No test exercises the real $__filters + broadcast-selection path to confirm the generated-SQL hook issues no ClickHouse/metadata query (the test mocks renderSourceFiltersToSql, hiding the call).
  • No test covers re-previewing a changed template (or changing variables/time range) while "Generated SQL" is expanded — the keepPreviousData asymmetry and collapse/flash behavior is unverified.
  • No test for the generated-SQL hook's own error path (parameterizedQueryToSql/renderSourceFiltersToSql throwing), which currently yields a silently absent section with no error UI.

No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond

@kodiakhq
kodiakhq Bot merged commit 3bdbf7f into main Nov 25, 2026
28 checks passed
@kodiakhq
kodiakhq Bot deleted the sql-filter-preview branch November 25, 2026 11:30

This branch was successfully deployed

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

Labels

automerge review/tier-3 Standard — full human review required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants