Skip to content

fix(semantic-layers): apply time-comparison offset to TEMPORAL_RANGE filters - #41556

Merged
rusackas merged 2 commits into
masterfrom
fix-sl-time-comparison
Jul 8, 2026
Merged

rusackas merged 2 commits into
masterfrom
fix-sl-time-comparison

Conversation

@betodealmeida

@betodealmeida betodealmeida commented Jun 29, 2026 •

Copy link
Copy Markdown
Member

SUMMARY

On semantic-view charts with a time comparison (time_compare) but no granularity set — i.e. modern x-axis or aggregate-only charts where the temporal column is only referenced inside a TEMPORAL_RANGE adhoc 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.py collided to produce this:

  • _get_time_filter short-circuited when query_object.granularity was empty, so the offset-aware bounds path was never reached.
  • _get_filters_from_query_object only skipped the TEMPORAL_RANGE pass-through when query_object.granularity was set, so the original (un-shifted) bounds were forwarded verbatim to both queries.
  • _convert_query_object_filter's TEMPORAL_RANGE handler has no notion of time_offset — it just emits literal gte/lt filters 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 in query_object.columns → col of any TEMPORAL_RANGE filter in query_object.filter. Both _get_time_filter and the TEMPORAL_RANGE skip in _get_filters_from_query_object now 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

  1. On a semantic-view-backed chart in Explore, set a time-range adhoc filter (e.g. 2020-01-01 : 2020-12-31 on a temporal column) and enable time_compare with 1 month ago. Run the chart.
  2. Inspect the response's query field: the two -- cube blocks should differ — the offset block's gte should be shifted back by one month (e.g. 2019-12-01T00:00:00) and its lt accordingly.
  3. The __1 month ago metric column in the result should now diverge from the base metric column.
  4. Backend regression: pytest --cov=superset/semantic_layers/ ./tests/unit_tests/semantic_layers/ --cov-fail-under=100 — 352 tests, 100% coverage.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@bito-code-review

bito-code-review Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #28bf0d

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 28aceec..28aceec
    • superset/semantic_layers/mapper.py
    • tests/unit_tests/semantic_layers/mapper_test.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@codecov

codecov Bot commented Jun 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.73%. Comparing base (b421813) to head (3d6fcd4).
⚠️ Report is 1 commits behind head on master.

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           
Flag Coverage Δ
hive 39.18% <3.33%> (-0.02%) ⬇️
mysql 57.83% <3.33%> (-0.02%) ⬇️
postgres 57.89% <3.33%> (-0.02%) ⬇️
presto 40.72% <3.33%> (-0.02%) ⬇️
python 59.32% <100.00%> (+0.01%) ⬆️
sqlite 57.47% <3.33%> (-0.02%) ⬇️
unit 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@betodealmeida
betodealmeida marked this pull request as ready for review June 29, 2026 22:47
@dosubot dosubot Bot added the explore:time Related to the time filters in Explore label Jun 29, 2026
@betodealmeida
betodealmeida requested a review from eschutho July 1, 2026 14:39

@mikebridge mikebridge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@betodealmeida
betodealmeida force-pushed the fix-sl-time-comparison branch from 28aceec to 3d6fcd4 Compare July 6, 2026 16:55
@pull-request-size pull-request-size Bot added size/XL and removed size/L labels Jul 6, 2026
Comment thread superset/semantic_layers/mapper.py Resolved
Comment thread superset/semantic_layers/mapper.py Resolved
Comment thread superset/semantic_layers/mapper.py Resolved
Comment thread superset/semantic_layers/mapper.py Resolved
@betodealmeida
betodealmeida requested a review from mikebridge July 6, 2026 17:36
@bito-code-review

bito-code-review Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #5f83d9

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: b90dcd4..3d6fcd4
    • superset/semantic_layers/mapper.py
    • tests/unit_tests/semantic_layers/mapper_test.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@rusackas rusackas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@rusackas
rusackas merged commit 001d6c9 into master Jul 8, 2026
62 checks passed
@rusackas
rusackas deleted the fix-sl-time-comparison branch July 8, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

explore:time Related to the time filters in Explore preset-io size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants