Skip to content

fix(semantic-layers): expose time grains in Explore for SemanticView datasources - #41456

Merged
sadpandajoe merged 3 commits into
masterfrom
sl-fix-time-grain
Jul 15, 2026
Merged

sadpandajoe merged 3 commits into
masterfrom
sl-fix-time-grain

Conversation

@betodealmeida

@betodealmeida betodealmeida commented Jun 26, 2026 •

Copy link
Copy Markdown
Member

SUMMARY

This PR makes time grains work the same way for SemanticView datasources as they do for SqlaTable ones, end-to-end across the frontend control panel, the explorable serialization, the query mapper, and the validation layer. It does not require any change on the semantic-layer extension side beyond what the core protocol already specifies; extensions can emit (time-column × grain) Dimension variants and the rest just works.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

This is a Cube semantic layer, but it works with any extension:

Screenshot 2026-06-26 at 2 14 42 PM

TESTING INSTRUCTIONS

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

@codecov

codecov Bot commented Jun 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.80%. Comparing base (4dc45aa) to head (a78e691).
⚠️ Report is 7 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #41456   +/-   ##
=======================================
  Coverage   64.80%   64.80%           
=======================================
  Files        2691     2691           
  Lines      149026   149077   +51     
  Branches    34393    34407   +14     
=======================================
+ Hits        96569    96613   +44     
- Misses      50691    50695    +4     
- Partials     1766     1769    +3     
Flag Coverage Δ
hive 39.16% <5.17%> (-0.03%) ⬇️
javascript 69.69% <100.00%> (ø)
mysql 57.82% <5.17%> (-0.04%) ⬇️
postgres 57.88% <5.17%> (-0.05%) ⬇️
presto 40.70% <5.17%> (-0.03%) ⬇️
python 59.35% <100.00%> (+0.02%) ⬆️
sqlite 57.46% <5.17%> (-0.04%) ⬇️
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 changed the title fix(semantic layers): improve time grain fix(semantic-layers): expose time grains in Explore for SemanticView datasources Jun 26, 2026
@betodealmeida
betodealmeida marked this pull request as ready for review June 26, 2026 18:17
@dosubot dosubot Bot added the explore:time Related to the time filters in Explore label Jun 26, 2026
@eschutho
eschutho self-requested a review June 26, 2026 19:10

@bito-code-review bito-code-review Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review Agent Run #d33c86

Actionable Suggestions - 1
  • tests/unit_tests/semantic_layers/mapper_test.py - 1
Additional Suggestions - 1
  • superset-frontend/src/explore/controlUtils/getSectionsToRender.ts - 1
    • Missing test for SemanticView · Line 70-73
      Added `DatasourceType.SemanticView` to `filterControlsForTypes` but no test exists for this new code path. Per rule [6262], tests should verify actual business logic — here the distinct filtering behavior (removing 'granularity' vs 'granularity_sqla'/'time_grain_sqla') for SemanticView types. Add a test case covering `DatasourceType.SemanticView` to prevent regressions as this datasource type matures.
Review Details
  • Files reviewed - 5 · Commit Range: 31199ae..7da95e4
    • superset-frontend/src/explore/controlUtils/getSectionsToRender.ts
    • superset/semantic_layers/mapper.py
    • superset/semantic_layers/models.py
    • tests/unit_tests/semantic_layers/mapper_test.py
    • tests/unit_tests/semantic_layers/models_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
    • Eslint (Linter) - ✔︎ 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

betodealmeida added a commit that referenced this pull request Jul 1, 2026
Reconcile with #41456: that PR sets ``expression=None`` on SV
dimensions so a truthy ``expression`` (the "adhoc SQL column" signal)
does not hide the time-grain selector. As a consequence, SV
dimensions with empty ``expression`` land in the popover's Simple
list, not the Saved list — the split in ``ColumnSelectPopover.tsx``
is done purely on ``expression`` truthiness. Disabling Simple would
leave dimensions unreachable in the popover, so only Custom SQL
stays disabled.

- Drop ``'simple'`` from ``effectiveDisabledTabs`` in
  ``DndColumnSelect.tsx`` and ``DndColumnMetricSelect.tsx``; keep
  ``'sqlExpression'``. Update comments to explain the tie to #41456.
- Rewrite the popover test to assert the new SV behavior (Simple
  enabled and selected by default; Custom SQL disabled; Saved
  enabled but not initial). Drop the ``as any`` cast per review.
- Remove PR-added "Saved tab" comment blocks in ``models.py`` — they
  will be misleading once #41456 lands with its own ``expression``
  rationale.
- Remove the four ``expression == "..."`` assertions in
  ``models_test.py`` for the same reason.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

@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.

Nice change — this wires time-grain support through the SemanticView datasource path so it behaves like SqlaTable end-to-end, and the unit coverage is genuinely behavioral. No blockers — leaving this as a Comment with a few things worth tightening before merge.

  1. Time-axis column silently dropped when no grain is selected and no raw variant exists (mapper.py:309-316). The loop only appends variants where dimension.grain == grain; a temporal column exposed only as grained variants (no grain=None), selected without a grain, matches nothing and drops out with no error — the chart loses its axis. Fall back to any available variant on no exact match, or guarantee a raw variant always accompanies grained ones. Add a test for this path.

  2. dimension.definition is dropped, but the comment claims it's preserved (models.py:335). definition isn't serialized anywhere. Either merge it into description or fix the comment to match the honest framing at models.py:365.

  3. _get_time_axis_column picks the first temporal column, which need not be the x-axis (mapper.py:900-932). With two temporal columns, the grain applies to whichever appears first. Identify the axis explicitly from the query context rather than a first-temporal heuristic.

This review was generated by Claude (AI) on behalf of @mikebridge.

@netlify

netlify Bot commented Jul 6, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit a78e691
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a4cfdf6bc28540007a223af
😎 Deploy Preview https://deploy-preview-41456--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

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
Comment thread superset/semantic_layers/mapper.py Resolved
Comment thread superset/semantic_layers/mapper.py Resolved
@bito-code-review

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

Copy link
Copy Markdown
Contributor

Code Review Agent Run #61fa4a

Actionable Suggestions - 0
Review Details
  • Files reviewed - 5 · Commit Range: 3be5d56..3630037
    • superset-frontend/src/explore/controlUtils/getSectionsToRender.ts
    • superset/semantic_layers/mapper.py
    • superset/semantic_layers/models.py
    • tests/unit_tests/semantic_layers/mapper_test.py
    • tests/unit_tests/semantic_layers/models_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
    • Eslint (Linter) - ✔︎ 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

betodealmeida added a commit that referenced this pull request Jul 7, 2026
Reconcile with #41456: that PR sets ``expression=None`` on SV
dimensions so a truthy ``expression`` (the "adhoc SQL column" signal)
does not hide the time-grain selector. As a consequence, SV
dimensions with empty ``expression`` land in the popover's Simple
list, not the Saved list — the split in ``ColumnSelectPopover.tsx``
is done purely on ``expression`` truthiness. Disabling Simple would
leave dimensions unreachable in the popover, so only Custom SQL
stays disabled.

- Drop ``'simple'`` from ``effectiveDisabledTabs`` in
  ``DndColumnSelect.tsx`` and ``DndColumnMetricSelect.tsx``; keep
  ``'sqlExpression'``. Update comments to explain the tie to #41456.
- Rewrite the popover test to assert the new SV behavior (Simple
  enabled and selected by default; Custom SQL disabled; Saved
  enabled but not initial). Drop the ``as any`` cast per review.
- Remove PR-added "Saved tab" comment blocks in ``models.py`` — they
  will be misleading once #41456 lands with its own ``expression``
  rationale.
- Remove the four ``expression == "..."`` assertions in
  ``models_test.py`` for the same reason.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@bito-code-review

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

Copy link
Copy Markdown
Contributor

Code Review Agent Run #b7de59

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset/semantic_layers/models.py - 1
    • Missing expression assertion in columns test · Line 340-346
      The `columns` property now sets `expression=None` for dimension columns but no test asserts this behavior. BITO.md rule [12101] requires type annotations on test functions, and rule [6262] requires tests to verify actual behavior logic. Add `assert col.expression is None` for each dimension column in the test.
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • superset/semantic_layers/mapper.py - 1
Review Details
  • Files reviewed - 5 · Commit Range: 93d3c87..a78e691
    • superset-frontend/src/explore/controlUtils/getSectionsToRender.ts
    • superset/semantic_layers/mapper.py
    • superset/semantic_layers/models.py
    • tests/unit_tests/semantic_layers/mapper_test.py
    • tests/unit_tests/semantic_layers/models_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
    • Eslint (Linter) - ✔︎ 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

Comment on lines +366 to +374
elif axis_variants:
# No variant matches the requested grain. Prefer the raw (grain=None)
# variant; otherwise pick a deterministic fallback so the axis stays
# on the query instead of being silently dropped.
raw_variant = next((v for v in axis_variants if v.grain is None), None)
dimensions.append(
raw_variant
if raw_variant is not None
else min(axis_variants, key=lambda v: v.grain.name if v.grain else "")

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.

superset/semantic_layers/mapper.py:366-374

When no time grain is requested at all and the time-axis column exposes only grained Dimension variants (no grain=None raw one), axis_match stays None here and the code falls through to min(axis_variants, key=lambda v: v.grain.name ...) — silently substituting an alphabetically-picked grain (e.g. "Day") for what should be raw data. _validate_granularity doesn't catch this since its grain-compatibility check only runs when a grain is actually requested.

Is it possible for a semantic view's time dimension to expose only grained variants with no raw one, or does the protocol guarantee a raw variant always exists? If it's possible, would it be worth surfacing an error (or defaulting more conservatively) instead of picking a grain silently here? WDYT?

This comment was generated by Claude (AI) on behalf of @eschutho.

@eschutho eschutho 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.

Just left one comment, but it looks good to me.

@sadpandajoe
sadpandajoe merged commit e28b259 into master Jul 15, 2026
67 checks passed
@sadpandajoe
sadpandajoe deleted the sl-fix-time-grain branch July 15, 2026 19:25
rdg0 pushed a commit to rdg0/superset that referenced this pull request Jul 20, 2026
mikebridge pushed a commit to mikebridge/superset that referenced this pull request Aug 31, 2026
…overage

Keep Saved-mode metric selection reachable for saved-only semantic views now
that Simple is disabled, and lock in unchanged behavior for tables and for
semantic views that declare ADHOC_COLUMN_EXPRESSIONS (expression-based
Simple/Saved classification, defaults, search, Save, no failure warning).
Strengthen the apache#41456 backend assertions so temporal semantic dimensions keep
expression=None alongside the new feature serialization.

Co-Authored-By: Claude Fable 5 <[email protected]>
mikebridge pushed a commit to mikebridge/superset that referenced this pull request Sep 4, 2026
…overage

Keep Saved-mode metric selection reachable for saved-only semantic views now
that Simple is disabled, and lock in unchanged behavior for tables and for
semantic views that declare ADHOC_COLUMN_EXPRESSIONS (expression-based
Simple/Saved classification, defaults, search, Save, no failure warning).
Strengthen the apache#41456 backend assertions so temporal semantic dimensions keep
expression=None alongside the new feature serialization.

Co-Authored-By: Claude Fable 5 <[email protected]>
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.

4 participants