Repository navigation
fix: filter Sunburst temporal segments by bucket and invert Hours offset in grained filters - #45598
Conversation
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
A dashboard Time Column filter sets the query granularity through extraFormData.granularity_sqla, so that level is bucketed by the time grain. Treat it as grained when building labels and cross-filters.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #45598 +/- ##
==========================================
+ Coverage 84.10% 84.14% +0.03%
==========================================
Files 3056 3057 +1
Lines 201285 201555 +270
Branches 47066 47146 +80
==========================================
+ Hits 169299 169600 +301
+ Misses 28747 28710 -37
- Partials 3239 3245 +6
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:
|
Samples queries replace every TEMPORAL_RANGE value with the chart's time_range, so drilling to detail on a grained segment returned every row of the dashboard time range. Match the bucket label on the grained column instead, as Timeseries does.
|
Manual check on a local docker-compose-light env (examples dataset
|
CodeAnt PR Risk: Low Risk
Assessed commit: |
rebenitez1802
left a comment
There was a problem hiding this comment.
Request changes: the fix works for its main case, reuses the shared drill-by helper, and follows the Timeseries cross-filter pattern. But the == temporal filters now send ISO strings instead of epoch values, which bypasses backend timestamp coercion. This PR also conflicts with #45571 on how Drill to detail should work.
🔴 High — Temporal == filters send ISO strings, which skip backend timestamp coercion
getSunburstDetailFilter (Sunburst/utils.ts:107-115) and the ungrained path through getSunburstFilter (utils.ts:82) produce val: '2003-11-14T00:00:00' from getTemporalXAxisDrillByFilter. The old Drill to detail code sent the raw epoch records[i]. filter_values_handler.handle_temporal_value (superset/models/helpers.py:4181-4186) only turns numbers or digit-only strings into engine-native literals via convert_dttm. An ISO string goes through as a plain varchar literal. That works on Postgres, but strictly typed engines such as Trino/Presto reject timestamp = varchar. So a right-click Drill to detail that worked before now errors there. Timeseries Drill to detail sends the raw number together with grain (EchartsTimeseries.tsx:637-640). Fix: for == temporal filters, keep val: value (the raw record) and add grain when the level is grained. Keep ISO strings only inside TEMPORAL_RANGE values.
🟡 Medium — This PR and #45571 disagree on grained Drill to detail and will conflict
This PR uses == plus grain because samples queries overwrite TEMPORAL_RANGE. #45571 uses TEMPORAL_RANGE because equality on a truncated column skips the dataset Hours offset. That concern is real: the grain filter path calls get_timestamp_expression without apply_dataset_offset, while the ring's grouping applies it. So with an offset, the Drill to detail row count can differ from the segment value. Both PRs also add test/Sunburst/EchartsSunburst.test.tsx as a new file (an add/add conflict) and edit the same contextmenu block and docs paragraph. #45571's isGrainedLevel is also already drifting from getSunburstTimeGrain. Fix: agree on one Drill to detail approach and one shared "is this level grained" helper used by both buildQuery and the click handlers, then stack one PR on the other.
🟡 Medium — Grain detection ORs the saved and dashboard time columns instead of using the effective one
getSunburstTimeGrain (utils.ts:40-44) treats a column as grained if it matches temporalColumnsLookup, granularitySqla or extraFormData.granularity_sqla. The backend grains only the effective granularity, where the dashboard value wins. Failure case: a chart with granularitySqla=d1, on a dashboard whose Time Column filter is set to d2. The backend returns raw d1 values, but the chart labels d1 segments "Oct 2003" and a click emits a whole-month range for what is a single day. The temporalColumnsLookup branch also grains every temporal level, while the semantic-view mapper only grains when there is exactly one temporal column. Fix: compare against extraFormData.granularity_sqla ?? granularitySqla, and add a test with two temporal levels.
🟡 Medium — Grains the frontend doesn't know silently match only the bucket start
For engine grains missing from TimeGranularity, getTimeBucketRange returns undefined. Examples: PT6H, PT5S, PT30S, PT0.5H, P0.25Y and TIME_GRAIN_ADDONS grains. getSunburstFilter then falls back to == on the raw column with no grain (utils.ts:73-82). The cross-filter targets get only the rows exactly at the bucket start, with no error. The label formatter also falls back to a full-day range, e.g. "2024-10-07 06:00:00 — 2024-10-07 23:59:59" for PT6H. Fix: when a grain is set but has no computable range, emit {op: '==', val: raw, grain} and keep the regular formatter.
🟡 Medium — Drill by bucket is overwritten when the query has a time_range
Drill by keeps the grained TEMPORAL_RANGE filter (EchartsSunburst.tsx:148-157). _apply_filters (query_context_factory.py:446-455) replaces every TEMPORAL_RANGE value with query_object.time_range. So on a dashboard with a time filter, Drill by from "Oct 2003" shows the whole dashboard range under an "Oct 2003" breadcrumb. Before, the query errored; now the wrong data is silent. Timeseries x-axis Drill by has the same behaviour, but this PR avoids exactly this for Drill to detail. Fix: use the same == plus grain filter for Drill by, or document this as a known limitation in the PR.
🟢 Low — The smart_date label change covers every grain, not just Month/Year
transformProps.ts:309-313 uses getTimeFormatterForGranularity, which returns a range formatter. Week labels become "2024-10-07 — 2024-10-13", which is long for a ring, and Day/Hour labels become full dates. Because categoricalColorScale is keyed by the label, saved label_colors keyed to the old labels also stop applying. Fix: use getSmartDateFormatter(grain) / getTooltipTimeFormatter from utils/formatters.ts, or limit the override to MONTH/QUARTER/YEAR. Then update the description and docs.
🟢 Low — Selection keys for temporal levels aren't backward compatible or timezone-stable
getSunburstSelectionKey (utils.ts:55-60) uses String(value). Temporal cross-filters saved before this change (label-based selectedValues in permalinks or dashboard state) no longer match any node, so the chart renders dimmed until the filter is cleared. For Date records, String(date) depends on the viewer's timezone. Fix: use date.getTime() for Date values; optionally fall back to matching on the label.
🟢 Low — time_range on the cross-filter narrows unrelated time filters on target charts
EchartsSunburst.tsx:95-98 mirrors Timeseries. The backend applies time_range to every TEMPORAL_RANGE filter on the target, including other columns and charts on datasets without this column, and it overrides the dashboard's native Time Range. Since this follows the Timeseries pattern, it's fine to keep, but it's worth one sentence in the docs.
🟢 Low — Docs paragraph is in the wrong section
The Sunburst cross-filter paragraph (exploring-data.mdx:499-502) sits under "Downloading Drill to Detail and Drill By Results". It belongs with cross-filtering. "Exclusive upper bound" also reads like an implementation detail.
🟢 Low — Test gaps
The YEAR case in transformProps.test.ts:111 also passes on master. Nothing covers week/day/hour labels, unknown grains, two temporal levels, effective time-column precedence, or the Hours offset. getSunburstDetailFilter builds a range filter and then throws it away; grain ? {col, op: '==', val, grain} : getSunburstFilter(...) would be clearer.
|
@rebenitez1802 I pushed 81df187 with the following changes for the body-only review:
Fail-before/pass-after proof: with source temporarily restored to reviewed head Siblings checked:
|
|
@rebenitez1802 I need to correct two claims in my earlier reply: #45598 (comment)
Fixed in
Regression test: Fail-before/pass-after: with the pre-fix Commands/results at this head: The first pre-commit attempt failed on formatting and a test typing error; the quoted result is the rerun after those corrections. Siblings checked:
Remaining: stacking with #45571 and adopting Remaining: the pre-existing Timeseries known-grain Drill by range/time_range behavior is unchanged. Browser acceptance and live Trino/BigQuery/Snowflake/MySQL execution were not run; the non-SQL-shift regression executes SQLite with the capability explicitly disabled. |
rebenitez1802
left a comment
There was a problem hiding this comment.
Request changes: thanks for the thorough round. Points 1, 3, 4, 6, 7, 8, 9 and 10 are fixed. I re-ran the Sunburst, Timeseries and xAxisDrillByFilter Jest suites (84 tests) and test_hours_offset_bound_truncation.py (121 tests) at cfb9605494, and all pass. But the Drill by change from my round-1 suggestion doesn't work end to end: Drill by drops grain before the request is sent. That's my mistake, sorry for sending you down that path.
🔴 High — Drill by drops grain, so a grained bucket matches only its start instant
getSunburstDetailFilter now feeds Drill by {op: '==', val: <epoch>, grain} (EchartsSunburst.tsx:151). But DrillByModal.tsx:244-250 turns every drill-by filter into an adhoc filter with simpleFilterToAdhoc, which keeps only subject/operator/comparator (simpleFilterToAdhoc.ts:88-99). convertFilter then emits {col, op, val}. So right-clicking "Oct 2003" on a Month-grained ring and choosing Drill by sends order_date = <2003-10-01 00:00> with no grain. That returns only rows at exactly midnight on Oct 1. At the previous head, the TEMPORAL_RANGE filter returned the whole month whenever the query had no time_range, so this is a regression from round 1. The new ...(grain && { grain }) in xAxisDrillByFilter.ts:156 is dropped the same way for both Timeseries Drill by callers. The test at EchartsSunburst.test.tsx:219-229 checks context.drillBy.filters[0].grain inside the plugin, so it doesn't catch this. The docs sentence "Drill to detail and Drill by retain the selected bucket" (exploring-data.mdx:500) is not true for Drill by. Fix: go back to the TEMPORAL_RANGE bucket for Drill by and keep the time_range overwrite as a documented limitation (same as Timeseries). Alternatively, carry grain through SimpleAdhocFilter → simpleFilterToAdhoc → convertFilter, which is a shared change better done in its own PR.
🟡 Medium — Epoch values in the shared helper break Timeseries Drill by on adhoc x-axes
getTemporalXAxisDrillByFilter now returns val: bucketLabel.getTime() (xAxisDrillByFilter.ts:155) when there's no grain or the grain is unknown. For an adhoc (custom SQL) column, simpleFilterToAdhoc writes the comparator straight into SQL, giving (expr) = 1785628800000. No backend coercion happens there, and Postgres rejects it with "operator does not exist: timestamp = bigint". On master the ISO string worked. Physical columns are fine only when convert_dttm returns a literal; the base convert_dttm returns None, so engines without an override fall back to the raw integer too. Fix: keep the ISO string for Drill by (the epoch value is needed only for Drill to detail and cross-filters), or have handle_temporal_value fall back to dttm.isoformat(sep=" ") when there's no native type or convert_dttm returns None.
🟡 Medium — The Hours-offset fix only covers == on engines without SQL shift
On Postgres/SQLite, apply_dataset_offset=op != TEMPORAL_RANGE (helpers.py:5375, 5416, 5451) shifts every grained operator. On other engines, the value adjustment is gated on op == utils.FilterOperator.EQUALS (helpers.py:5527). So a Table/AG Grid IN + grain cross-filter on __timestamp (TableChart.tsx:601), on a dataset with an Hours offset, is fixed on Postgres but still matches the wrong buckets on Trino/Snowflake/BigQuery. shift_temporal_value already handles lists. Fix: extend the gate to IN, NOT_IN and NOT_EQUALS, or restrict the SQL shift to EQUALS so both engine groups behave the same.
🟡 Medium — The backend change affects every chart's grained filters; please retitle or split it
The helpers.py change also changes Drill to detail results for Timeseries, BigNumber, Mixed Timeseries and Pivot Table, plus Table/AG Grid IN + grain cross-filters, on any dataset with an Hours offset. They're correctness fixes, but a fix(sunburst) title and description don't mention them. The change also reverses #43173's pinned behaviour: test_grained_adhoc_filter_sql_is_unchanged is renamed to ..._applies_dataset_offset. Fix: split the helpers.py change into its own fix(models) PR and ask @sadpandajoe to review it (they wrote #43173). If you'd rather keep one PR, retitle it and list the affected charts in the description.
🟢 Low — The timezone check doesn't match pandas for an invalid timezone
The value adjustment is skipped whenever get_dataset_timezone() returns anything (helpers.py:5530). Pandas, however, falls back to the Hours offset when the timezone fails to resolve (utils/core.py:2198-2203). So a dataset with a misspelled timezone and an Hours offset gets 0 Drill to detail rows. test_grained_drill_with_dataset_timezone_ignores_hours_offset only uses "UTC". Fix: reuse the same timezone validity check as pandas, or add an invalid-timezone case.
🟢 Low — Legacy label fallback causes false highlighting
transformProps.ts:351 checks filterState.selectedValues[0].includes(...), a substring match on one string. Year labels are digit-only, so they match digits inside the new 13-digit epoch keys. For example, selecting 2004 gives "1072915200000,…", which contains "2000", so the 2000 segment stays lit. This only affects how the chart looks. Fix: split the key on , and compare element by element.
🟢 Low — Ungrained temporal equality with an Hours offset is still off
This happens on every engine and isn't new. Pandas adds the offset to displayed values, but the ungrained filter compares the raw column (the adjustment needs filter_grain). So Drill to detail on an ungrained temporal level silently returns a different row. Fix: mention it under "Remaining" and narrow the docs wording at exploring-data.mdx:500-502.
🟢 Low — Reply says base.py:579 was "fixed", but that file isn't changed
superset/db_engine_specs/base.py:579 is only the supports_temporal_column_shift default, which the new code reads; git diff 37e5c78a86 cfb9605494 doesn't touch it. A nit, just so the record is accurate.
🟢 Low — #45571 coordination is still open
Merging this first and having #45571 import getSunburstTimeGrain is the right order. #45571 also has its own timeGrain.ts with different rules: it grains every temporal level when no time column is set. It also has a broader helpers.py change that would shift TEMPORAL_RANGE + grain twice. That change should be dropped in favour of this one.
|
@rebenitez1802 I found another gap in my previous reply: #45598 (comment) Fixed in Regression tests in
Fail-before/pass-after (Docker, same tests with Commands/results: Initial test-setup/type-check iterations were corrected before the quoted final runs. I removed the test containers with Siblings checked:
Remaining:
|
The horizontal time-axis path calls the same temporal drill helper as the vertical path. Ungrained equality filters intentionally use epoch milliseconds so the backend can coerce native timestamp literals; formattedVal remains the ISO display label.
Drill by converts filters to adhoc filters that keep only column, operator and comparator, so an equality filter's grain never reached the query. A grained Sunburst segment now drills by its TEMPORAL_RANGE bucket, like Timeseries. The shared x-axis helper sends the naive ISO datetime again: adhoc expressions and labels write the comparator into SQL without coercion, where an epoch integer fails on typed engines. Sunburst cross-filters and Drill to detail keep epochs for physical columns and use ISO datetimes for adhoc levels. Segment highlighting compares selection keys level by level, so a year label no longer matches digits inside an epoch key.
normalize_dttm_col falls back to the Hours offset when the dataset timezone does not resolve, and the SQL temporal shift is skipped for any configured timezone. Grained bucket filters now invert the display-only offset in that case on every engine instead of matching nothing.
|
@rebenitez1802 Follow-up to review #45598 (review), at head 62cef72. "Fail before" below means the test fails with the source files from 9e35745 (the reviewed head plus one test-only commit) and passes at the fixing commit. 🔴 Drill by drops
🟡 Epoch values break Timeseries Drill by on adhoc x-axes — fixed in 4e8c60e.
🟡 Hours-offset fix only covers
🟡 Backend change affects every chart's grained filters — partly done, at 62cef72. I retitled the PR to 🟢 Timezone check doesn't match pandas — fixed in 62cef72. The gate checks whether the timezone resolves (
🟢 Legacy label fallback false highlighting — fixed in 4e8c60e. Highlighting compares keys level by level (
🟢 Ungrained temporal equality with an Hours offset — not fixed. I narrowed the docs at 🟢 🟢 #45571 coordination — open, see Remaining. Validation at 62cef72: Remaining:
|
|
@rebenitez1802 One more item for Remaining in #45598 (comment), found by an independent check of that reply at head 62cef72: on a dataset with a valid non-UTC timezone (America/Los_Angeles) and an Hours offset of 1, a grained |
rebenitez1802
left a comment
There was a problem hiding this comment.
Approve: thanks, every round-2 point is fixed. I re-ran the Sunburst, Timeseries, xAxisDrillByFilter and DrillBy Jest suites (130 tests) and the offset/helpers/sqla pytest suites (878 passed; the only failure is a missing sqlalchemy_bigquery in my env) at 62cef72cee.
One non-blocking docs suggestion is inline. It describes a limitation that exists on master too, so it's not a reason to hold the PR.
A correction to my round-2 note: I said the round-1 TEMPORAL_RANGE Drill by "returned the whole month whenever the query had no time_range". That only holds when the chart has no Time Range filter at all, for the reason in the inline comment.
|
@rebenitez1802 thanks for the approval. The one ask in it, the inline docs suggestion on |
SUMMARY
Sunburst (frontend):
TEMPORAL_RANGE. Exact matches on physical columns send epoch milliseconds so the backend can produce engine-native timestamp literals; adhoc SQL levels send a naive ISO datetime, because an adhoc expression has no native type to convert an epoch into. Engine-specific grains without frontend bucket arithmetic keepgrainon their equality filters.==plusgrain, which survives the chart/dashboardtime_rangeoverride.TEMPORAL_RANGEbucket, like Timeseries Drill by. Drill by converts filters withsimpleFilterToAdhoc, which keeps only column, operator and comparator, so agrainwould be dropped. Known limitation, shared with Timeseries: a chart or dashboard Time Range replaces that range, and an engine-specific grain without a fixed length matches only the bucket start.getTemporalXAxisDrillByFilterhelper (both Timeseries Drill by callers) keeps master's naive ISO datetime for exact matches.Grained filters with a dataset Hours offset (backend,
superset/models/helpers.py, all charts):==,!=,IN,NOT IN,<,<=,>,>=) use the same expression as grouping on engines with SQL temporal-shift support. On engines without it, the display-only Hours offset is removed from each selected bucket value before comparison. An unresolvable dataset timezone falls back to the Hours offset, as pandas does.IN+grainon the time column). It also reverses the behavior pinned by fix(dataset): correct Hours Offset filter bounds and grain-truncation order #43173:test_grained_adhoc_filter_sql_is_unchangedbecomestest_grained_adhoc_equality_filter_applies_dataset_offset.Related: #45571 supplies Sunburst Explore grain controls/query configuration. Landing plan: #45571 lands first; this PR then merges master and adopts its
timeGrain.ts. Neither PR's base or ready-for-review state is changed here.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Historical captures below predate this review follow-up; browser acceptance was not rerun. The Drill by request shape changed after these captures (grained segments use a bucket range, exact values an ISO datetime).
Screenshots
Captured at
37e5c78a. Local docker-compose-light env, examples dataset cleaned_sales_data; charts and dashboard created for this check.Before/after payload evidence:
superset-frontend/plugins/plugin-chart-echarts/test/Sunburst/EchartsSunburst.test.tsxexpects timestamps instead of formatted names and Month/Year bucket ranges;superset-frontend/plugins/plugin-chart-echarts/test/Sunburst/transformProps.test.tsexpects distinguishable year-bearing labels.TESTING INSTRUCTIONS
Commands run at
62cef72cee285fa71d1b5d43fe44a69ea48422ff:Plugin TypeScript: exit 0. Jest: 1615 passed, 1 skipped (123 suites). Docker Python: 881 passed. Pre-commit: exit 0.
superset-frontend/src/components/Chart/DrillBy/DrillByTemporalFilters.test.tsxfollows the real Drill by request path: it right-clicks a rendered Sunburst segment, opensDrillByModalwith the resulting filters and checks the posted chart-data request aftersimpleFilterToAdhocandconvertFilter.Manual verification to repeat: select raw and grained temporal segments; inspect cross-filter and both drill results with a dashboard Time Range, a dashboard Time Column override, two temporal hierarchy levels, adhoc temporal levels, engine-specific grains, and positive/negative dataset Hours offset. Compare bucket counts and row identities rather than just SQL compilation. Live Trino/BigQuery/Snowflake/MySQL execution was not run; the engine-capability tests use SQLite with the SQL-shift flag switched.
ADDITIONAL INFORMATION