Skip to content

fix(app): hydrate source fields for raw SQL tiles in all chart rendering contexts#2503

Closed
pulpdrew wants to merge 1 commit into
mainfrom
cursor/fix-raw-sql-source-hydration-1a6d
Closed

fix(app): hydrate source fields for raw SQL tiles in all chart rendering contexts#2503
pulpdrew wants to merge 1 commit into
mainfrom
cursor/fix-raw-sql-source-hydration-1a6d

Conversation

@pulpdrew

Copy link
Copy Markdown
Contributor

Summary

Raw SQL tiles referencing source-dependent macros ($__sourceTable, $__filters) failed with "Macro '$__sourceTable' requires a source to be selected" when rendered outside the Dashboard Tile component (e.g. in notebook tiles). This happened because the saved config only stores the source ID — the runtime fields (from, metricTables, implicitColumnExpression, etc.) were never merged before query execution in those contexts.

The fix adds a hydrateRawSqlConfigFromSource() helper to the useQueriedChartConfig and useRenderedSqlChartConfig hooks. This mirrors the hydration pattern already established in DBDashboardPage's Tile useEffect, ensuring macros resolve correctly in all chart rendering contexts (dashboards, notebooks, chart explorer, SQL preview).

Key design decisions:

  • The hydration is a no-op for non-raw-SQL configs (builder, promql), so existing Dashboard tiles continue to work identically
  • The helper is exported for reuse by future chart rendering contexts
  • Source metadata is only merged when both a source ID is present on the config AND the source has been fetched successfully

How to test on Vercel preview

Preview routes: /chart

Steps:

  1. Navigate to /chart and switch to SQL mode via the segmented control
  2. Select a Connection and Source
  3. Write a SQL query using $__sourceTable (e.g. SELECT count() FROM $__sourceTable)
  4. Click Run
  5. Verify the query executes without the error "Macro '$__sourceTable' requires a source to be selected"

References

Linear Issue: HDX-4594

Open in Web Open in Cursor 

…onfig

Raw SQL tiles referencing source-dependent macros (, )
failed with 'Macro requires a source to be selected' when rendered outside the
Dashboard Tile component (e.g. in notebook tiles), because the saved config only
stores the source ID — the runtime fields (from, metricTables, etc.) were not
merged before query execution.

Add hydrateRawSqlConfigFromSource() to useQueriedChartConfig and
useRenderedSqlChartConfig hooks. This mirrors the hydration pattern already
established in DBDashboardPage's Tile useEffect, ensuring macros resolve
correctly in all rendering contexts.

Fixes HDX-4594

Co-authored-by: Drew Davis <pulpdrew@gmail.com>
@changeset-bot

changeset-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b5ebff2

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 23, 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 23, 2026 2:59pm
hyperdx-storybook Ready Ready Preview, Comment Jun 23, 2026 2:59pm

Request Review

@greptile-apps

greptile-apps Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes raw SQL tiles that used source-dependent macros ($__sourceTable, $__filters) failing in non-dashboard rendering contexts (notebooks, chart explorer) by adding a hydrateRawSqlConfigFromSource() helper that merges source metadata into the config before query execution.

  • Introduces hydrateRawSqlConfigFromSource<T>() which picks from, implicitColumnExpression, useTextIndexForImplicitColumn, bodyExpression (log sources), metricTables (metric sources), and sampleWeightExpression from the fetched source into the raw SQL config, mirroring the hydration already performed in DBDashboardPage's Tile useEffect.
  • Applies the helper in both useQueriedChartConfig and useRenderedSqlChartConfig, replacing config with hydratedConfig in query keys and query functions so macros resolve identically in all rendering contexts.

Confidence Score: 4/5

Safe to merge; the change correctly extends source hydration to all chart rendering contexts with no risk to non-raw-SQL paths.

The implementation is correct and the helper is a no-op for non-raw-SQL configs. The isSourceLoading gate was already present before this PR. The only gap is a dropped explanatory comment.

No files require special attention beyond the minor dropped comment in useChartConfig.tsx.

Important Files Changed

Filename Overview
packages/app/src/hooks/useChartConfig.tsx Adds hydrateRawSqlConfigFromSource helper and applies it in both useQueriedChartConfig and useRenderedSqlChartConfig; logic correctly mirrors the Dashboard Tile useEffect with one minor dropped comment
.changeset/fix-raw-sql-source-hydration.md Changeset entry for patch release; accurately describes the fix

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

Reviews (1): Last reviewed commit: "fix(app): hydrate source fields for raw ..." | Re-trigger Greptile

const sql = parameterizedQueryToSql(query);
// sql-formatter can't handle prometheusQuery() / CTE syntax in PromQL queries
if (isPromqlChartConfig(config)) {
if (isPromqlChartConfig(hydratedConfig)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Dropped sql-formatter comment

The comment explaining why PromQL queries skip format() was removed when config was renamed to hydratedConfig. The formatter still cannot handle prometheusQuery() / CTE PromQL syntax, so the guard still needs the explanation. Without it, future readers may not understand why PromQL is returned early.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

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

@github-actions

Copy link
Copy Markdown
Contributor

E2E Test Results

All tests passed • 219 passed • 3 skipped • 1384s

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

Tests ran across 4 shards in parallel.

View full report →

@pulpdrew pulpdrew closed this Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants