Skip to content

Commit e81334c

Browse files
feat(ag-grid-table): add a Tree query mode (#46490)
1 parent 549595d commit e81334c

122 files changed

Lines changed: 29753 additions & 56 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/superset-e2e.yml‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,23 @@ jobs:
301301
INCLUDE_MOBILE: "true"
302302
with:
303303
run: playwright-run "${{ matrix.app_root }}" mobile/
304+
- name: Run Playwright (Table V2 Tree mode)
305+
# cached-dependencies is a submodule (not a plain directory), and
306+
# the $/ self-repository syntax resolves action files directly from
307+
# the repository without performing a real (submodule-aware)
308+
# checkout, so it can't see into a submodule's link. Keep this one
309+
# on the workspace-relative ./ form, consistent with every other
310+
# workflow in the repo that references this action.
311+
uses: ./.github/actions/cached-dependencies # zizmor: ignore[self-repository] - $/ cannot resolve an action that lives in a submodule; ./ is required here
312+
env:
313+
NODE_OPTIONS: "--max-old-space-size=4096"
314+
# Scoped to this step for the same reason as Soft-delete and
315+
# Embedded above: the Tree mode flags must not alter
316+
# Flask's configuration for the other steps' servers.
317+
SUPERSET_FEATURE_TABLE_V2_TREE_MODE_ENABLED: "true"
318+
SUPERSET_FEATURE_AG_GRID_TABLE_ENABLED: "true"
319+
with:
320+
run: playwright-run "${{ matrix.app_root }}" explore/tree-table-keyboard.spec.ts
304321
- name: Set safe app root
305322
if: failure()
306323
id: set-safe-app-root
Lines changed: 276 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
---
2+
title: 'Table V2: Tree mode'
3+
hide_title: true
4+
sidebar_position: 12
5+
version: 1
6+
---
7+
8+
## Table V2: Tree mode
9+
10+
:::note
11+
Tree mode is in development and gated by the `TABLE_V2_TREE_MODE_ENABLED`
12+
feature flag. Its behavior can change between releases.
13+
:::
14+
15+
The Tree query mode of Table V2 shows a hierarchy from one dataset. Expand a row to see
16+
its detail fields and a table of its children. Each child can expand in turn;
17+
the last level can open to show its detail fields without another table.
18+
19+
### Enable Tree mode
20+
21+
An operator must enable both flags in `superset_config.py`:
22+
23+
```python
24+
FEATURE_FLAGS = {
25+
"AG_GRID_TABLE_ENABLED": True,
26+
"TABLE_V2_TREE_MODE_ENABLED": True,
27+
}
28+
```
29+
30+
Merge these entries into your deployment's existing feature flags. Both flags
31+
are off by default. After restarting Superset, choose **Table V2** and set
32+
**Query mode** to **Tree**. Aggregate and Raw records keep their existing behavior.
33+
34+
### Prepare one dataset
35+
36+
All levels use columns from the same dataset. The chart does not join separate
37+
datasets. A dataset row carries the child fields and repeats its ancestors'
38+
fields. For example:
39+
40+
| session_id | session_started_at | channel | step_id | step_started_at | step_name | duration |
41+
| --- | --- | --- | --- | --- | --- | --- |
42+
| S1 | 2026-01-01 09:00:00 | Web | A1 | 2026-01-01 09:00:10 | Start | 10 |
43+
| S1 | 2026-01-01 09:00:00 | Web | A2 | 2026-01-01 09:00:20 | Finish | 20 |
44+
| S2 | 2026-01-01 10:00:00 | App | B1 | 2026-01-01 10:00:10 | Start | 15 |
45+
46+
Use stable IDs at every level. Each child has a link column containing the
47+
parent ID. At deeper levels, the complete ancestor path identifies a row:
48+
an ID repeated under different ancestors has separate expansion state.
49+
For a temporal ID stored in a custom format, such as a year stored as an
50+
integer, configure the dataset column's Python date format to match the
51+
stored value.
52+
53+
Parent columns must be identical on every dataset row for that parent,
54+
including the level-1 time column. The parent query groups by the configured
55+
columns; inconsistent repeated values can produce several visible rows with
56+
the same ID. Duplicate parent IDs share their children. A null or empty parent
57+
ID cannot expand.
58+
59+
Child IDs must not be null; null child IDs are excluded from child queries.
60+
Child level columns must be the same on every dataset row for one child ID;
61+
otherwise the count and Load more can disagree. This includes displayed and
62+
detail fields: totals count distinct child IDs, while queries group by the
63+
projected fields. Children without a matching visible ancestor are not shown.
64+
65+
### Configure levels in Explore
66+
67+
Choose **Table V2**, set **Query mode** to **Tree**, and open **Levels**. For the example:
68+
69+
| Setting | Level 1 | Level 2 |
70+
| --- | --- | --- |
71+
| Name / plural | Session / Sessions | Step / Steps |
72+
| ID column | session_id | step_id |
73+
| Linked to Session by | — | session_id |
74+
| Time column | session_started_at | step_started_at |
75+
| Columns | channel | step_name, duration |
76+
| Detail fields | session_started_at | step_started_at |
77+
| Default sort | session_id ascending | step_id ascending |
78+
79+
Set a singular name and, optionally, a plural name for each level.
80+
Without a plural name the singular name is reused. Detail regions use the
81+
level's name followed by “details”.
82+
83+
Hover or focus a field's information icon for a short explanation of that setting.
84+
85+
Use **Add level** for more levels. Each child level needs its own ID and parent
86+
link column. The parent link must differ from the child's own ID column.
87+
Choose Columns for the table and Detail fields for the expanded
88+
key-value block. Set the default sort for each level. A level with detail fields
89+
can expand even when it has no children.
90+
91+
Level 1 requires a time column. A child time column is required when
92+
**Apply date filter to children** is enabled, and must also appear in that
93+
level's Columns or Detail fields. Configure the initial child batch with the
94+
shown-per-parent setting; the default is 100.
95+
Typed values below 1 become 1, values above 1000 become 1000, and an emptied
96+
field returns to the default of 100 when you leave it.
97+
98+
In **Query**, set filters, the parent row limit, and page length. The **Page Size**
99+
menu lists 10, 20, 50, 100, and 200 parents per page in ascending order. The
100+
default is 50. The parent row limit caps the available parents, independently of
101+
the child and export limits.
102+
The default parent row limit is 10000 and uses Table V2's row-limit control.
103+
Page length is a Tree-only setting, independent of Aggregate and Raw records.
104+
Tree uses the instance's `SQL_MAX_ROW` cap regardless of retained server
105+
pagination settings. Tree uses its own page length and falls back to 50 for a
106+
missing or invalid value. Aggregate and Raw records keep their server page length.
107+
108+
### Filters and date ranges
109+
110+
Non-date dashboard filters and the chart's own non-date filters select the
111+
top-level parents. On-screen children are fetched for those parent paths,
112+
subject to dataset access, row-level security, and date rules. Non-date filters
113+
are not reapplied to the on-screen child rows.
114+
115+
The chart's time range (the first time range in its filters) and dashboard
116+
time filters apply to the level-1 time column, whichever column they name,
117+
including in children and Load more queries. This preserves the selected
118+
parents' range. A dashboard time filter replaces the chart's own time range.
119+
When the dashboard filter is cleared or set to **No filter**, the chart keeps
120+
its own time range, as other charts do. An explicit **No filter** time range
121+
in the chart removes its date limit. Any further time range an author adds on another column keeps that column and
122+
applies to parents, children and exports alike.
123+
**Apply date filter to children**, off by default, additionally applies the
124+
level-1 range to the child level's time column; ranges on other columns do not
125+
carry to children's time columns. Enabled ancestor date rules also carry into
126+
deeper levels.
127+
128+
A matching child never restores an excluded parent. A visible parent with no
129+
children matching the child date rule stays visible and shows
130+
“No Steps in the selected range” when the configured plural name is Steps.
131+
Dataset-provided child-count columns do not automatically recalculate for that
132+
range.
133+
134+
### Expand, sort, and load more
135+
136+
Opening the first row loads the first child batch for **every parent on that
137+
page**, not just the row opened. Further opens use the loaded children.
138+
**Load more** fetches the next batch for that parent; the status shows how many
139+
children are loaded and the total. A leaf with detail fields needs no child
140+
query to open its details.
141+
142+
**Expand all** operates on the current page. When multiple levels can open,
143+
its arrow menu offers **Expand to Sessions**, **Expand to Steps**, and the
144+
equivalent action for each configured level. The main button changes to
145+
**Collapse all**. There is no search control.
146+
The main button reflects the last expand or collapse action immediately.
147+
Selecting the deepest openable level from the menu shows **Collapse all**;
148+
a partial selection keeps **Expand all** while deeper levels remain closed.
149+
Collapsing while children are loading keeps rows closed when those responses arrive.
150+
If a refresh adds a collapsed parent to the page, the button shows **Expand all** again.
151+
152+
Click a column header or press Enter on a focused header to sort that level.
153+
The configured default column alternates between the opposite direction and
154+
the configured direction. Other columns cycle through ascending, descending,
155+
and a return to the default sort. If the level has no configured default, all
156+
columns use the three-step cycle and clearing the sort restores ascending ID
157+
order. Child sorting is shared by every child table at that level on the page,
158+
refetching its first batches. Parent page or sort changes collapse rows.
159+
Auto-refresh retains open rows and reloads their children; manual Force refresh
160+
collapses them. Changing chart or dashboard filters, including the time range,
161+
returns to the first parent page. A manual refresh with the same query keeps
162+
the current page.
163+
164+
Child batches have a 100,000-row query cap, which an operator's lower query
165+
limit can further constrain. A batch can be cut before every parent's children
166+
arrive, especially with large parents or deep expansion. Affected rows show
167+
“Couldn't load Steps —” and a separate **Retry** button. Retry reloads that
168+
parent alone, keeping the count query. A Load more failure also offers Retry
169+
for that next batch. Child requests run synchronously even when global async
170+
queries are enabled, so deployment query timeouts apply.
171+
172+
### Exports and reports
173+
174+
**Export to .CSV** and **Export to Excel** include every matching child of
175+
the parents across the chart's pages, regardless of which rows are expanded
176+
or loaded on screen.
177+
The output is flat: one row per deepest-level child, with ancestor IDs,
178+
columns, and detail fields repeated. With two levels, each Step gets a row
179+
carrying its Session fields. Identical dataset rows for one child give one
180+
export row, as on screen.
181+
182+
Non-date filters choose parents. Children follow the same date filters as
183+
the screen. The export uses the viewer's parent sort and each child level's
184+
configured default sort, rather than the child header sort clicked on screen.
185+
186+
With non-date filters, parent selection is capped at the chart's row limit or
187+
the operator's `SQL_MAX_ROW`, whichever is lower. An engine may reject a large
188+
parent ID list or SQL statement. Lower the chart's row limit if that happens.
189+
Without non-date filters, an export can include parents beyond the chart's
190+
row limit.
191+
192+
The export row cap is the operator's `SQL_MAX_ROW` setting (100,000 by default).
193+
As with other Superset chart exports, CSV/Excel exports and scheduled CSV
194+
reports stop silently at this limit. The operator can raise `SQL_MAX_ROW` to
195+
allow larger exports.
196+
197+
Parents whose ID is NULL or empty can't expand on screen. CSV and Excel
198+
exports include these as parent rows without children. Regular exports also
199+
include a row for each parent with zero children in the selected child date
200+
range. A streaming CSV can omit parents with no children in range.
201+
Streaming selection depends on the configured threshold and parent row limit
202+
or expected-row estimate, not on a count of all export children.
203+
204+
Scheduled CSV reports use the same export path and cap. A text report shows
205+
the first page of parents only, without children. With every row collapsed,
206+
image downloads from the chart menu contain the parent grid without the Tree
207+
toolbar and pager.
208+
Scheduled screenshot reports start with rows collapsed because expansion state
209+
is not saved.
210+
211+
### Limits
212+
213+
- An image download with open rows, or a dashboard image, can show the grids'
214+
hidden paging controls and a misplaced pager. A separate image-export fix in
215+
Superset corrects this.
216+
- A temporal ID or link column stored as a number or string with a date format matches children only when the dataset has no hour offset or timezone shift.
217+
- Temporal IDs stored as strings with non-zero microseconds in a `%f` field are unsupported.
218+
- **Export Current View** is not offered in Tree mode. **Export to full .CSV/Excel**
219+
is offered when `ALLOW_FULL_CSV_EXPORT` is enabled and includes children under the same export cap.
220+
- Right-click opens the browser menu; **Drill to detail** is in the chart menu.
221+
- Switching between Tree and the other modes keeps both modes' settings. A saved
222+
chart keeps the other mode's settings as unused values.
223+
- Page length resets to 10 when server pagination is off and the page-length control becomes hidden.
224+
- The Results pane shows only the parent page, without a separate count-query tab.
225+
- CSV/Excel hold all children of each parent, up to the export row cap; the screen shows the first N per parent, with **Load more** to show the next N.
226+
- A child query for multiple parents reads the children of every parent in the batch before trimming the results to the configured number per parent.
227+
- If the operator's `SQL_MAX_ROW` is lower than the number of count rows in a child batch, some parents can show no children where you would otherwise see **Couldn't load** with a **Retry** button.
228+
- Clearing a dashboard time filter or choosing **No filter** keeps the chart's
229+
own time range.
230+
- Children on screen and in exports are limited by their parent path, dataset
231+
access and row-level security, the level-1 date range, and the optional child
232+
date filter. In a virtual dataset, Jinja (`filter_values`, `get_filters`) sees
233+
non-date filters in parent queries on screen and in exports. Child queries
234+
receive the selected parent IDs and date filters.
235+
- Cells show raw values: there are no number formats (D3 or currency),
236+
conditional formatting, column settings or HTML rendering. The Customize tab
237+
is empty in Tree mode.
238+
- Matrixify, Drill by, and time comparison are not supported.
239+
- **View query** shows the parent queries only, not the children's SQL.
240+
- Child queries stay synchronous when global async queries are enabled.
241+
- The dashboard **Export to Excel** workbook writes the first page of parents,
242+
without children, and a separate sheet with the parent count.
243+
- A Tree chart switched to the legacy Table chart keeps the Tree query mode and runs as Aggregate.
244+
- Editing a Tree chart through the MCP `update_chart` tool reports success without changing what the chart shows.
245+
- The MCP `get_chart_data` tool returns only the parent page for Tree charts.
246+
- An empty result shows the grid's own "No Rows To Show" message, and Expand all stays enabled.
247+
- Tree mode uses its own pager, which looks different from the Aggregate and Raw records pager.
248+
- A new level sorts by its ID column until another default sort is chosen.
249+
- A scheduled PNG report can fail with a blank screenshot when only one to three parents match.
250+
251+
### When Tree mode is turned off
252+
253+
A saved chart in Tree mode shows **Tree mode is turned off**, including when
254+
no parents match its filters. Its Levels settings remain available in Explore,
255+
and an author can switch to Aggregate or Raw records. The data API, CSV/Excel
256+
exports and CSV reports still work because the flag controls frontend rendering.
257+
Image and PDF reports show the flag-off message. Table V2 itself still requires
258+
`AG_GRID_TABLE_ENABLED`; disabling that flag unregisters the chart.
259+
260+
### Keyboard and accessibility
261+
262+
Use Tab and Shift+Tab to move through controls, headers, rows, expanded child
263+
tables, Retry, and Load more. Arrow keys navigate grid cells. Enter or Space
264+
on a row's expand cell or button toggles its open area; the button announces
265+
Expand/Collapse and its expanded state. Header controls support keyboard
266+
sorting. The grids are nested grids with named child groups, rather than a
267+
single treegrid.
268+
269+
The page-size selector and pager are keyboard accessible; Enter activates page
270+
controls. User-triggered loading, completion, and errors are announced through
271+
live status text. After a successful Retry, focus moves to the row's expand
272+
button. Load more keeps focus on the button while more children are
273+
available. After the last batch, focus moves to the first new row and the chart
274+
and page keep their scroll positions.
275+
If the last batch adds no rows, focus moves to the last existing child row,
276+
and if you moved focus elsewhere during loading, it stays there.

‎docs/static/feature-flags.json‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@
123123
"default": false,
124124
"lifecycle": "development",
125125
"description": "Enable Table V2 time comparison feature"
126+
},
127+
{
128+
"name": "TABLE_V2_TREE_MODE_ENABLED",
129+
"default": false,
130+
"lifecycle": "development",
131+
"description": "Shows the Tree query mode in Table V2 (AG Grid table)"
126132
}
127133
],
128134
"testing": [

‎superset-frontend/packages/superset-ui-chart-controls/src/types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ export type InternalControlType =
228228
| 'HeaderGroupsControl'
229229
| 'HiddenControl'
230230
| 'JSEditorControl'
231+
| 'LevelsControl'
231232
| 'SelectAsyncControl'
232233
| 'SelectControl'
233234
| 'SliderControl'

‎superset-frontend/packages/superset-ui-core/src/query/types/PostProcessing.ts‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,32 @@ interface _PostProcessingRank {
241241
}
242242
export type PostProcessingRank = _PostProcessingRank | DefaultPostProcessing;
243243

244+
interface _PostProcessingFirstNPerGroup {
245+
operation: 'first_n_per_group';
246+
options: {
247+
groupby: string[];
248+
n: number;
249+
};
250+
}
251+
export type PostProcessingFirstNPerGroup =
252+
| _PostProcessingFirstNPerGroup
253+
| DefaultPostProcessing;
254+
255+
interface _PostProcessingTreeRows {
256+
operation: 'tree_rows';
257+
options: {
258+
levels: {
259+
id_column: string;
260+
columns: string[];
261+
time_column?: string;
262+
}[];
263+
bounds?: [string | null, string | null][];
264+
};
265+
}
266+
export type PostProcessingTreeRows =
267+
| _PostProcessingTreeRows
268+
| DefaultPostProcessing;
269+
244270
interface _PostProcessingHistogram {
245271
operation: 'histogram';
246272
options?: {
@@ -274,7 +300,9 @@ export type PostProcessingRule =
274300
| PostProcessingRename
275301
| PostProcessingFlatten
276302
| PostProcessingHistogram
277-
| PostProcessingRank;
303+
| PostProcessingRank
304+
| PostProcessingFirstNPerGroup
305+
| PostProcessingTreeRows;
278306

279307
export function isPostProcessingAggregation(
280308
rule?: PostProcessingRule,

‎superset-frontend/packages/superset-ui-core/src/utils/featureFlags.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export enum FeatureFlag {
7777
EnableDashboardDownloadWebDriverScreenshot = 'ENABLE_DASHBOARD_DOWNLOAD_WEBDRIVER_SCREENSHOT',
7878
TableV2TimeComparisonEnabled = 'TABLE_V2_TIME_COMPARISON_ENABLED',
7979
AgGridTableEnabled = 'AG_GRID_TABLE_ENABLED',
80+
TableV2TreeModeEnabled = 'TABLE_V2_TREE_MODE_ENABLED',
8081
}
8182

8283
export type ScheduleQueriesProps = {

0 commit comments

Comments
 (0)