You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 3bdbf7f
Browse filesBrowse the repository at this point in the historyBrowse files
feat: show generated SQL in the SQL query filter preview (#3823)
## 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
| <img width="651" height="939" alt="Screenshot 2026-11-25 at 10 32 34" src="https://github.com/user-attachments/assets/ae0aaa76-708f-4534-b431-2996635c0550" /> | <img width="684" height="905" alt="Screenshot 2026-11-25 at 10 33 05" src="https://github.com/user-attachments/assets/21886405-2242-4d8d-be12-e623cef432ef" /> |
| :----- | :---- |
### 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:
```sql
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
0 commit comments