Repository navigation
fix(semantic-layers): apply time-comparison offset to TEMPORAL_RANGE filters - #41556
Conversation
Code Review Agent Run #28bf0dActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #41556 +/- ##
=======================================
Coverage 64.72% 64.73%
=======================================
Files 2686 2686
Lines 148683 148707 +24
Branches 34322 34327 +5
=======================================
+ Hits 96240 96264 +24
Misses 50678 50678
Partials 1765 1765
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:
|
mikebridge
left a comment
There was a problem hiding this comment.
The main-path fix looks correct and well-tested — centralizing time-axis resolution in _get_time_axis_column so the skip condition and bound emission can't drift is the right call, and the regression test is well-targeted. Two things worth a look before merge:
1. Parallel group-limit path still uses the old granularity-gated logic. _get_group_limit_filters gates both its inner time-bound emission (mapper.py:891) and its TEMPORAL_RANGE skip (mapper.py:936-938) on query_object.granularity — the predicate this PR replaced everywhere else. A chart with no granularity plus a series limit and a time offset reproduces the same identical-bounds bug one layer down. Same root cause. Route this through _get_time_axis_column too, or note it explicitly as out of scope with a follow-up ref.
2. Unconditional TEMPORAL_RANGE skip can drop one-sided ranges. The skip is now unconditional (mapper.py:384), but _get_time_filter only emits bounds when both from_dttm and to_dttm resolve (mapper.py:517). The old handler emitted a one-sided filter for open-ended ranges ("2020-01-01 : " → gte only). An open-ended or underivable range now yields no time filter, silently widening the scan. Consider gating the skip on whether bounds were actually emitted, and add a test with from_dttm/to_dttm unset.
This review was generated by Claude (AI) on behalf of @mikebridge.
28aceec to
3d6fcd4
Compare
Code Review Agent Run #5f83d9Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
rusackas
left a comment
There was a problem hiding this comment.
Nice, @betodealmeida, LGTM. Resolving the temporal column through granularity → columns → TEMPORAL_RANGE.col and only skipping the pass-through when the bounds actually got emitted reads right.
One thing I noticed, not a blocker: the skip is column-agnostic, so a query with two TEMPORAL_RANGE filters on different temporal columns would drop the non-axis one once bounds are emitted. It's the same behavior the granularity path already had, so no regression... just flagging it in case it bites someone later.
SUMMARY
On semantic-view charts with a time comparison (
time_compare) but nogranularityset — i.e. modern x-axis or aggregate-only charts where the temporal column is only referenced inside aTEMPORAL_RANGEadhoc filter — the offset query was emitted with the same date bounds as the main query, so the two metric values were always identical.Three things in
superset/semantic_layers/mapper.pycollided to produce this:_get_time_filtershort-circuited whenquery_object.granularitywas empty, so the offset-aware bounds path was never reached._get_filters_from_query_objectonly skipped the TEMPORAL_RANGE pass-through whenquery_object.granularitywas set, so the original (un-shifted) bounds were forwarded verbatim to both queries._convert_query_object_filter's TEMPORAL_RANGE handler has no notion oftime_offset— it just emits literalgte/ltfilters from the input range.Net effect: main and offset Cube requests were byte-for-byte identical → identical responses → time comparison was a no-op.
Fix introduces a new
_get_time_axis_column(query_object, all_dimensions)helper that resolves the temporal column from any of three sources, in order:query_object.granularity→ first temporal entry inquery_object.columns→colof any TEMPORAL_RANGE filter inquery_object.filter. Both_get_time_filterand the TEMPORAL_RANGE skip in_get_filters_from_query_objectnow consult this helper, so the offset-aware code path takes over and the TEMPORAL_RANGE pass-through is skipped whenever a time axis is identifiable.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
2020-01-01 : 2020-12-31on a temporal column) and enabletime_comparewith1 month ago. Run the chart.queryfield: the two-- cubeblocks should differ — the offset block'sgteshould be shifted back by one month (e.g.2019-12-01T00:00:00) and itsltaccordingly.__1 month agometric column in the result should now diverge from the base metric column.pytest --cov=superset/semantic_layers/ ./tests/unit_tests/semantic_layers/ --cov-fail-under=100— 352 tests, 100% coverage.ADDITIONAL INFORMATION