← Back to Pull requests

feat: add an "All" option to SQL query dashboard filters #3861

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 30, 2026 10:25 UTC
Author

Summary

SQL query dashboard filters can now offer "All", which selects every option the filter's query returns. Stacked on #3847, which added "All" for static list filters.

  • The SQL query filter settings get the Include "All" option checkbox, hidden for single-select filters.

  • The dashboard page loads the options of SQL query filters with "All" selected and fills them in for tiles. It runs the same query as the filter's dropdown, so the result is shared, not fetched twice.

  • Tiles that reference the variable wait for the options, and show an error when they can't be loaded or there are more than 1,000. The tile editor's preview does the same.

  • The SQL query filter form explains, under its SQL editor, how "All" on other filters behaves in its options query.

  • The external API and MCP accept allowAll on SQL query filters. MCP query_tile and query_tiles with all: true run the filter's query to fill in its options.

  • The 1,000-option cap is documented in the checkbox, OpenAPI and MCP descriptions.

  • toSqlQueryFilterValues and the values query settings moved to common-utils so the app and MCP run the query the same way.
  • Behaviour notes

  • In tiles, "All" makes $variable and $__filter use every returned option; $__conditionalAll becomes 1=1.

  • In dependent filter queries, including filter-editor previews, a SQL query filter's "All" means no constraint: both macros become 1=1, while bare $variable becomes NULL. Use macros for these dependencies to avoid filtering out every option. Static-list "All" still supplies its full option list; $__conditionalAll remains unconstrained.

  • Tiles and tile-editor previews that reference the variable wait for its options. Failed queries or more than 1,000 options show an error instead of running; unrelated tiles remain usable.

  • Empty results behave like nothing selected: bare $variable becomes NULL, and both macros become 1=1.

  • The options query stops after 30 seconds and returns partial results. The filter, tiles that use its "All", and MCP tile runs then show a warning that the list may be incomplete. Tiles still run.

  • MCP expands every SQL query filter passed all: true; one failed or over-cap filter fails the whole call, even for unrelated tiles.
  • How to test

    <details>
    <summary>On this branch, import this dashboard to ClickStack and follow the instructions:</summary>

    {"version":"0.1.0","name":"TEST: SQL query All — tiles and editor","tags":["testing","sql-filters","all-option"],"tiles":[{"id":"6b0d3d27e6df08cb05ff4ef4","x":0,"y":0,"w":24,"h":7,"config":{"name":"Start here","source":"","displayType":"markdown","markdown":"**Keep Region set to All; change Scenario to test.** This demo uses 1,002 synthetic rows (region IDs 0–1001), so no telemetry data is needed.\n\n- **Ready:** 3 options → bare / filter / conditionalAll = **3 / 3 / 1,002**.\n- **At limit:** 1,000 options → **1,000 / 1,000 / 1,002**.\n- **Over limit:** 1,001 options → dependent tiles and editor previews show the cap error.\n- **Query error:** deliberate options-query failure → dependent tiles and editor previews show the error.\n- **Loading:** about 10 seconds of loading, then **5 / 5 / 1,002**. Change **Run** to repeat with an uncached query.\n- **Empty:** zero options → **0 / 1,002 / 1,002**, the documented empty-selection behavior.\n\nThe **Unrelated control** must stay at **1,002**, even while other tiles are blocked.","select":[],"where":""}},{"id":"6b0d3d27e6df08cb05ff4ef5","x":0,"y":7,"w":6,"h":4,"config":{"displayType":"number","numberFormat":{"output":"number","mantissa":0,"thousandSeparated":true},"configType":"sql","sqlTemplate":"SELECT count() AS \"Matching rows\"\nFROM (SELECT number AS region_id, toString(number) AS region, $__fromTime_ms AS ts FROM numbers(1002))\nWHERE $__timeFilter_ms(ts)\n  AND region IN ($region)\nLIMIT 1","connection":"Local ClickHouse","name":"Bare variable — selected IDs"}},{"id":"6b0d3d27e6df08cb05ff4ef6","x":6,"y":7,"w":6,"h":4,"config":{"displayType":"number","numberFormat":{"output":"number","mantissa":0,"thousandSeparated":true},"configType":"sql","sqlTemplate":"SELECT count() AS \"Matching rows\"\nFROM (SELECT number AS region_id, toString(number) AS region, $__fromTime_ms AS ts FROM numbers(1002))\nWHERE $__timeFilter_ms(ts)\n  AND $__filter(region, $region)\nLIMIT 1","connection":"Local ClickHouse","name":"Filter macro — selected IDs"}},{"id":"6b0d3d27e6df08cb05ff4ef7","x":12,"y":7,"w":6,"h":4,"config":{"displayType":"number","numberFormat":{"output":"number","mantissa":0,"thousandSeparated":true},"configType":"sql","sqlTemplate":"SELECT count() AS \"Matching rows\"\nFROM (SELECT number AS region_id, toString(number) AS region, $__fromTime_ms AS ts FROM numbers(1002))\nWHERE $__timeFilter_ms(ts)\n  AND $__conditionalAll(region IN ($region), $region)\nLIMIT 1","connection":"Local ClickHouse","name":"conditionalAll — unconstrained on All"}},{"id":"6b0d3d27e6df08cb05ff4ef8","x":18,"y":7,"w":6,"h":4,"config":{"displayType":"number","numberFormat":{"output":"number","mantissa":0,"thousandSeparated":true},"configType":"sql","sqlTemplate":"SELECT count() AS \"Matching rows\"\nFROM (SELECT number AS region_id, toString(number) AS region, $__fromTime_ms AS ts FROM numbers(1002))\nWHERE $__timeFilter_ms(ts)\nLIMIT 1","connection":"Local ClickHouse","name":"Unrelated control — always 1,002"}},{"id":"6b0d3d27e6df08cb05ff4ef9","x":0,"y":11,"w":12,"h":7,"config":{"displayType":"table","configType":"sql","sqlTemplate":"SELECT\n  region_id AS \"Region ID\",\n  if(region IN ($region), 'kept', 'dropped') AS \"Bare variable\",\n  if($__filter(region, $region), 'kept', 'dropped') AS \"Filter macro\",\n  if($__conditionalAll(region IN ($region), $region), 'kept', 'dropped') AS \"conditionalAll\"\nFROM (SELECT number AS region_id, toString(number) AS region, $__fromTime_ms AS ts FROM numbers(1002))\nWHERE $__timeFilter_ms(ts)\nORDER BY region_id\nLIMIT 12","connection":"Local ClickHouse","name":"Which sample rows each expression keeps"}},{"id":"6b0d3d27e6df08cb05ff4efa","x":12,"y":11,"w":12,"h":7,"config":{"name":"Markdown expansion — also guarded in the editor","source":"","displayType":"markdown","markdown":"**Selected region values:** [$region]\n\nThis tile should show the same loading or error message as the query tiles when its options are unavailable. Its editor preview should do the same.\n\nAt the 1,000-option boundary this list is long; use the number tiles to check the count.","select":[],"where":""}},{"id":"6b0d3d27e6df08cb05ff4efb","x":0,"y":18,"w":24,"h":7,"config":{"name":"Editor checks and recovery","source":"","displayType":"markdown","markdown":"**Editor check**\n1. Choose **Over limit** or **Query error**, leaving **Region = All**.\n2. Open **Edit** on **Filter macro — selected IDs**. With **Apply filters** on, the preview must show the same unavailable message as the tile.\n3. Turn **Apply filters** off → **1,002**. Turn it back on → blocked again.\n4. Close the editor and switch **Scenario** back to **Ready** → **3**.\n\n**Loading:** select **Loading**, then immediately open the editor. If cached, change **Run** first or while Loading is selected. There should be no temporary unfiltered number.\n\n**Selection semantics:** with Ready selected, clear Region → **0 / 1,002 / 1,002**; pick one ID → **1 / 1 / 1**; restore All → **3 / 3 / 1,002**.\n\nAll queries are synthetic and read-only. The time picker does not change the sample IDs. For MCP validation, pass Scenario and Region explicitly; MCP ignores these saved defaults and intentionally fails the whole call for an unavailable All filter.","select":[],"where":""}}],"filters":[{"id":"6b0d3d27e6df08cb05ff4efc","name":"Scenario","variableName":"scenario","maxSelections":1,"type":"STATIC_LIST","options":["Ready","At limit","Over limit","Query error","Loading","Empty"],"isBroadcastEnabled":false,"isVariableEnabled":true},{"id":"6b0d3d27e6df08cb05ff4efd","name":"Region","variableName":"region","type":"SQL_QUERY","connection":"Local ClickHouse","sqlTemplate":"WITH ifNull(arrayElement([$scenario], 1), 'Ready') AS scenario\nSELECT toString(number) AS region\nFROM numbers(multiIf(scenario = 'At limit', 1000, scenario = 'Over limit', 1001, scenario = 'Empty', 0, scenario = 'Loading', 5, 3))\nWHERE throwIf(scenario = 'Query error', 'Intentional SQL All options failure') = 0\n  AND sleepEachRow(if(scenario = 'Loading', 2., 0.)) = 0\n  AND ifNull(arrayElement([$run], 1), '1') != ''\nLIMIT 1001\nSETTINGS max_block_size = 1, max_threads = 1","allowAll":true,"isBroadcastEnabled":false,"isVariableEnabled":true},{"id":"6b0d3d27e6df08cb05ff4efe","name":"Run","variableName":"run","maxSelections":1,"type":"STATIC_LIST","options":["1","2","3"],"isBroadcastEnabled":false,"isVariableEnabled":true}],"containers":[],"savedFilterValues":[{"type":"variable","name":"scenario","values":["Ready"]},{"type":"variable","name":"region","values":[],"all":true},{"type":"variable","name":"run","values":["1"]}]}
    

    </details>

    References

  • Linear Issue: HDX-6191

  • Related PRs: #3830, #3847
  • <!-- CURSOR_SUMMARY -->
    ---

    [!NOTE]

    Medium Risk

    Changes how dashboard tiles and MCP resolve SQL variables when "All" is selected, including live ClickHouse option queries, 1,000-option limits, and macro expansion semantics that affect query correctness across dependent filters.

    > Overview

    This PR extends "All" dashboard filter support from static lists to SQL query filters via an allowAll setting (external API, OpenAPI, MCP schemas). When All is selected, tiles need the filter’s options query result expanded into variable values (cap 1,000); until then they block with loading/error placeholders, and warn if the options query hits the 30 s cutoff.

    > The app adds useExpandedSqlQueryVariables, wires expanded variables into tiles and the tile editor (including markdown preview), surfaces cut-off cautions on SQL filter dropdowns, and exposes the Include "All" option checkbox on SQL query filter settings with SQL-specific help text.

    > common-utils centralizes values-query settings (SQL_QUERY_FILTER_VALUES_SETTINGS), result normalization, cut-off detection, and expansion error messages. MCP query_tile / query_tiles mirror the dashboard by running expandSqlQueryAllVariables when variables use all: true, failing on load errors or >1,000 options and attaching per-tile warnings when lists may be incomplete.

    > Dependent filter/options queries treat a sibling SQL filter’s All as no constraint ($__filter / $__conditionalAll → 1=1, bare $variable → NULL); static-list All still supplies full option values.

    > <sup>Reviewed by Cursor Bugbot for commit d7aee3ed379f3f4728ed26b88cb882890cfdc846. Bugbot is set up for automated code reviews on this repo. Configure here.</sup>

    <!-- /CURSOR_SUMMARY -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: pulpdrew Review duration: 5234m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #3861"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.7% · Safe to merge
    27.7%