Repository navigation
fix(sunburst): keep the saved time grain in Explore - #45571
aminghadersohi merged 18 commits into
Conversation
A Sunburst saved with a grain on a temporal hierarchy level kept the grain only in granularity_sqla/time_grain_sqla. The Sunburst control panel has neither control, so Explore dropped both and queried the level at its raw (daily) values. Give the Sunburst panel a Time grain control (shown when a hierarchy level is temporal, no default grain for new charts) and the hidden temporal_columns_lookup control. buildQuery and the server-side query builder send each temporal level as a BASE_AXIS column reference carrying the grain, and drop a dormant grain that has no temporal level or legacy granularity subject. The MCP temporal-state check accepts a grain whose subject is a hierarchy level the lookup marks temporal.
… levels buildQuery and the server-side builder grain only physical columns marked temporal, so an adhoc level alone no longer shows a grain that would be dropped from the query.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #45571 +/- ##
===========================================
+ Coverage 65.35% 84.27% +18.92%
===========================================
Files 3057 3058 +1
Lines 201579 202017 +438
Branches 47149 47261 +112
===========================================
+ Hits 131747 170255 +38508
+ Misses 66866 28518 -38348
- Partials 2966 3244 +278
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ime bucket A grained temporal level holds the start of its time bucket, so the drill-to-detail filter compared the column to that single instant: drilling into a monthly segment returned only the rows stamped exactly at midnight on the first of the month (usually none). The detail filter for a grained level now carries the grain that buildQuery applied (the dashboard grain first), the same way the Timeseries chart drills into its time axis. Raw temporal, categorical and adhoc levels are unchanged.
The shared check returns a boolean rather than a type predicate, since a false result does not mean the column is adhoc; buildQuery narrows to a physical column itself before building the column reference.
|
Acceptance run against a local docker-compose-light stack (examples
Found and fixed in 18f0389 and 98eb82e: drill to detail on a monthly segment returned 0 rows because the detail filter compared Not changed here, also present on the merge base: a cross-filter from a temporal ring sends the formatted label ( |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
A Sunburst drill on a grained temporal ring sends the bucket as a TEMPORAL_RANGE in local time. Run the ring query and both drill queries against real rows on a dataset with a 5 hour offset and check each bucket's drill returns exactly the rows the ring counted.
|
Acceptance of the drill range change, at 9d8c2ac (local docker-compose-light env, examples data). Drill to detail and Drill by on a grained temporal ring both send the bucket as a
The offset dataset puts each row near a day boundary, so the offset moves rows between months (October 2004: 159 rows without the offset, 170 with it); the ring value and both drills agree on 170. I added Also re-checked: a Sunburst saved without a grain sends the same drill filters as before this change; embedded guests load the grained charts (8/8), and a forged grained column outside the hierarchy is still rejected (403). Not related to this change and unchanged from master: Drill by on a temporal ring without a grain still sends the formatted label (for example Screenshots in the description are updated to this head. |
CodeAnt PR Risk: Low Risk
Assessed commit: |
rebenitez1802
left a comment
There was a problem hiding this comment.
Request changes: the Explore time grain fix (the control, buildQuery and the server-side mirror) is sound, and the embedded-guest anti-tamper check still holds. But the new drill filters return the wrong rows whenever a time range or legacy granularity_sqla applies (details inline).
🟡 Medium — Conflicts with #45598 and contradicts its drill design
Both PRs edit EchartsSunburst.tsx and exploring-data.mdx, and both add test/Sunburst/EchartsSunburst.test.tsx; git merge-tree against #45598's head (37e5c78) reports conflicts in all three. They choose opposite Drill to detail shapes: TEMPORAL_RANGE here, == + grain there. They also duplicate the "is this level grained" check (isGrainedLevel here, getSunburstTimeGrain there), and only #45598's version honours a dashboard Time Column override (extraFormData.granularity_sqla). Fix: pick one drill design, land one PR first, and rebase the other onto a shared helper.
🟡 Medium — Two temporal levels on a semantic view fail in Explore
Both levels become BASE_AXIS columns. _get_grain_time_axis_column (superset/semantic_layers/mapper.py:1298-1320) returns None when more than one temporal dimension is selected, so _validate_granularity (:1500-1505) raises "A time column must be specified when a time grain is provided" (reproduced with an order_date + ship_date view). Before this PR only a dashboard grain override reached this path; the new control makes it a normal Explore action. The new mapper tests cover only one temporal level.
🟢 Low — Unknown or engine-specific grains fall back to an exact-instant match
getTimeBucketRange returns undefined for grains it doesn't handle (PT5S, PT30S, PT0.5H, PT6H, P0.25Y, TIME_GRAIN_ADDONS entries). getTemporalXAxisDrillByFilter then emits {op: '==', val: <bucket start>} with no grain, which matches only rows stamped exactly at the bucket start. Fix: the == + grain shape suggested inline covers every grain; otherwise add grain to the fallback.
🟢 Low — Unrelated changes in the diff
The #: source-location line added to messages.pot is the only one in the file and will go stale. Two unrelated lambdas in tests/unit_tests/security/manager_test.py (around lines 4302 and 4339) were reformatted.
|
@rebenitez1802, I applied the review-body changes in 80118e7, with adhoc drill transport in e3492ea:
Remaining: landing order and merging the overlapping files with #45598 are not completed here. I did not rebase or edit that branch. This branch supplies the equality-plus-grain drill contract and shared helper for the sibling worker to consume with a normal merge after the first PR lands. Siblings checked:
Final head: |
|
@rebenitez1802 Follow-up to #45571 (comment) Remaining: the two For the broader factory change, I retained the chart-independent behavior and added regression coverage in d4351c6. Evidence: Siblings checked:
Validation at this head: Docker Python 3.11 runs using |
rebenitez1802
left a comment
There was a problem hiding this comment.
Request changes: the round-1 drill fix works end to end, and the rest of round 1 is addressed apart from the deferred #45598 reconciliation. Three blockers remain, all inline:
- CI is red on the
semantic_layerscoverage gate. - Existing Explore code writes to the new hidden
granularity_sqlacontrol, which silently turns the grain off. - The factory change breaks Timeseries Drill to detail under a dashboard Time Column override.
On the round-1 fix: I sent the drill payloads through QueryContextFactory with a dashboard time range, legacy granularity, a Time Column override, and a dataset with an Hours offset (Postgres/SQLite). Each ring bucket returns exactly its own rows.
rebenitez1802
left a comment
There was a problem hiding this comment.
Request changes: one narrow blocker remains, with a one-click fix inline. The three round-2 blockers are fixed and CI is green. I also checked the drill fix end to end through get_samples and the CSV/XLSX export. After the #45598 merge, the Hours offset is applied exactly once: shifted in SQL on Postgres/SQLite, inverted on the filter value elsewhere, never both.
|
@rebenitez1802 I closed the remaining ask in your review at #45571 (review) . Fixed in 0fb8d33. I limited the different-Time-Column Sunburst exception to non-extra filters, as suggested. Dashboard cross-filters on the replaced column are dropped; independent Sunburst drill predicates survive. Regression test: tests/unit_tests/models/test_sunburst_drill_hours_offset.py::test_sunburst_factory_drops_extra_filter_on_replaced_time_column, added in this commit. Through QueryContextFactory.create and SQLite query execution, all three variants (samples, drill_detail, full) failed before the fix (only ['z'] instead of the five expected bucket rows), and pass after. The test also asserts that the independent grain-bearing predicate survives. Docker pytest: 136 focused tests passed; additional branch suites: 859 passed. Jest: 147 passed. Branch-scoped pre-commit passed with repository-pinned Ruff 0.9.7. Siblings checked:
|
rebenitez1802
left a comment
There was a problem hiding this comment.
Approve: every blocker from the earlier rounds is fixed, and CI is green.
- Sunburst drills use
==plus the grain, and the backend no longer overwrites them. - The hidden
granularity_sqlacontrol is gone. - The semantic-layer coverage gate passes.
- Stale dashboard cross-filters on a replaced Time Column are dropped.
- After the #45598 merge, the Hours offset is applied exactly once.
One non-blocking suggestion inline, for older Sunbursts on semantic views.
|
@rebenitez1802 I checked the approval body; its only remaining suggestion is the legacy semantic-view grain compatibility covered by the two inline threads. Fixed in ba1e5ab. The mirror preserves the grain when the saved lookup is absent or null, but still removes it for an explicit empty lookup. Regression: Siblings checked:
|
- DrillDetailPane.test.tsx and tests/unit_tests/views/datasource/test_utils.py: both sides appended tests (this branch's lower-bound Samples paging, master's sunburst chart-type tests from #45571); kept both. - superset/views/datasource/utils.py: #45571 retyped get_samples' payload from SamplesPayloadSchema to dict[str, Any] and dropped the import; the branch's _count_star_query_context now takes the same type, and the test that needed a type: ignore for the old one no longer does. - Translations: took master's catalogs and re-ran scripts/translations/babel_update.sh on a tracked-files snapshot of the merged tree; against master only this branch's msgids and each file's POT-Creation-Date change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
SUMMARY
Explore rebuilds form data from the chart's controls. Retain the saved Sunburst Time Grain so opening a saved chart in Explore applies it to its temporal hierarchy levels.
Design. The Sunburst panel has a Time grain control, shown for physical temporal hierarchy levels, with no initial grain for new charts. The hidden lookup retains temporal metadata; there is no hidden Time Column control. The dataset lookup selects all physical temporal levels, and a legacy Time Column can additionally identify a hierarchy level without disabling other lookup-marked levels. Query columns become
BASE_AXISphysical references withtimeGrain; saved hierarchy columns remain names. Explore saves the lookup inparams. The server-side query builder uses the same lookup-or-legacy-subject rule.grain, including engine-specific grains. The backend applies the dataset Hours offset before truncation and retains independent bucket predicates when their Time Column is unchanged. A Time Column override that replaces a different temporal column discards filters on that replaced column, restoring the existing fallback for Timeseries drill payloads.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Screenshots
Sunburst saved with Time Grain = Month, opened in Explore: the control shows Month and the order_date ring has one segment per month (180 rows)
Hierarchy of categorical columns only: the Time Grain control is hidden and no grain is sent
Explore, Time Grain changed to Year: the same ring regroups by year (21 rows)
Dashboard with a Time Grain native filter set to Month: the grained Sunbursts show months, including one saved without a grain
Same dashboard after changing the Time Grain filter to Year: both temporal rings regroup by year; the categorical chart is unchanged
Drill to detail on the October 2004 segment of a monthly ring: the filter identifies the month's bucket and the modal lists that month's 159 rows (same as a direct SQL count)
Drill by product line from the October segment on a dataset with a 5 hour offset: the filter identifies the bucket and the slices add up to the ring's 170 rows
Historical captures at
9d8c2acb; drill payloads at this head use equality plus grain rather than temporal ranges. Local docker-compose-light env at the PR head, examples dataset cleaned_sales_data (order_date 2003-01 to 2005-05) plus a virtual dataset over it with a 5 hour Hours offset.Before: an MCP-created Sunburst with a monthly temporal level returns 3 rows through MCP but 90 daily rows when opened in Explore. After: Explore shows the Time grain control set to Month and queries the 3 monthly rows.
TESTING INSTRUCTIONS
generate_charttool, or in Explore by choosing Time grain = Month).Automated:
npx jest src/explore/controlUtils/sunburstTimeGrain.test.ts plugins/plugin-chart-echarts/test/Sunburstpytest tests/unit_tests/mcp_service/chart/test_sunburst_chart.py tests/unit_tests/security/manager_test.py tests/unit_tests/semantic_layers/mapper_test.py tests/unit_tests/common/test_form_data_query_context.py tests/unit_tests/models/test_sunburst_drill_hours_offset.pyRegression checks cover time-range/granularity rewrites through
QueryContextFactory.create, exact per-category bucket membership with a dataset Hours offset, lookup-marked grains under legacy Time Column overrides, Explore dataset edits and dashboard/chart-type carryover, semantic multi-level grouping and drill variants, malformed temporal lookups, hidden-control resets, and typed form-data fields. Source reverts reproduce the failures; the raw-level assertion also rejects aTEMPORAL_RANGEmutation.Scope and landing plan:
Sunburst/timeGrain.tshelper. Bucket cross-filters and inverted Hours-offset behavior are retained.ADDITIONAL INFORMATION