Skip to content

fix(semantic-layer): ignore inapplicable time grains - #46339

Merged
mikebridge merged 3 commits into
apache:masterfrom
mikebridge:fix-semantic-dormant-time-grain
Nov 19, 2026
Merged

mikebridge merged 3 commits into
apache:masterfrom
mikebridge:fix-semantic-dormant-time-grain

Conversation

@mikebridge

Copy link
Copy Markdown
Member

TL;DR

Fix semantic-view charts that fail when a time grain is attached to a text grouping. A new Bar chart grouped by a text field should work with the default Day grain, just as it does for a SQL dataset. Time range filters still apply.

Background

Chart builders attach a time grain (Day by default) to the x-axis of Bar, Line, Area, Scatter and Mixed charts, even when that axis is a text field. Dashboards can also add a query-level grain to charts that group by no date field.

Problem

SQL datasets ignore a grain that cannot apply to the grouping. Semantic views refused it, so a new chart grouped by a text field could fail before the user changed any time settings. Saved query contexts and direct API requests could encounter the same refusal.

What this changes

Semantic views ignore a grain on a known non-date field when that field has no advertised grain variants. They also ignore a query-level grain when no date is grouped. A field that advertises grain variants retains its grain, even if its default representation is text or numeric. Time range filters continue to use the raw date field; this change does not redirect them to another column.

SUMMARY

The mapper uses the existing Arrow date/time/timestamp classification and the full dimension metadata to distinguish an inapplicable grain from a requested, supported grouping. Validation and mapping use the same condition. The input query object is not rewritten, so stored contexts and original chart-data cache keys remain intact. SQL datasets are unchanged, and there is no cache format change.

Validation still refuses:

  • A grain the semantic view does not support on a date field.
  • Unknown or unresolved fields; unknown metadata is not treated as a known categorical field.
  • A grain on a text field named as the legacy time column when time bounds are present. The bounds are not redirected to another field.

Known limits:

  • Legacy is_timeseries requests that ask for bucketing without a grouped time column remain unbucketed on semantic views, as before. An unsupported grain in that shape is no longer refused.
  • A date-typed field without grain variants still rejects an unsupported default grain.
  • For a hand-built API request with a categorical legacy time column and bounds, a grain attached to that column is refused even if its columnType is not BASE_AXIS.
  • A categorical legacy time column without bounds suppresses the query-level grain, including with a separately grouped date column. A grain explicitly attached to the date column is still applied and validated.

Verification on this tree:

  • 1,491 focused unit tests passed, covering the semantic mapper/models, dimension resolution, common query actions and MCP chart helpers, plus related model tests.
  • Changed-file pre-commit hooks passed, including MyPy, Ruff and Pylint.
  • The earlier full unit run on this exact tree had 40,843 passed, 59 failed and 224 errors. All 283 failure/error cases and messages matched the accepted baseline; no new failures were found. The full local suite is not globally green.
  • Regression coverage includes advertised grain variants, unknown metadata, unsupported date grains, raw time bounds, categorical legacy refusal, saved query replay and unchanged cache keys. QueryObjectFactory tests exercise dashboard time-range requests with both attached and query-level grains.
  • Four earlier builder checks on this tree passed for Bar, Line, Mixed and Table requests with a dashboard time range.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

No browser or live-warehouse check has been done on this PR, and no screenshot is available yet. The behavior described above is covered by local automated checks; manual validation remains outstanding.

TESTING INSTRUCTIONS

Automated regression checks:

pytest tests/unit_tests/semantic_layers/mapper_test.py -k 'dormant_grain or categorical_legacy'

Manual checks still to run with a configured semantic view exposing a text grouping, a date dimension with raw/Day/Month variants, and a metric:

  1. Create a Bar chart with the text field on the x-axis and leave the default Day grain. Verify categorical grouping works. Repeat for Line, Area, Scatter and Mixed.
  2. Put the chart on a dashboard with a time range and Day/Month grain. Verify the range filters the raw date field while the text grouping stays unchanged. Repeat with a chart that has no date in its grouped columns.
  3. Group by the date field and select Day and Month. Verify the advertised variant is used; request an unsupported grain and verify refusal.
  4. Replay a stored text-axis query context and verify it succeeds without rewriting the saved context.
  5. Submit a categorical legacy time column with a grain and bounds; verify refusal. Verify unresolved fields are still rejected.
  6. Compare with a SQL dataset to confirm its behavior is unchanged.

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

Draft for review; no frontend code, schema migration, new flag or public API shape change.

@github-actions github-actions Bot added the doc Namespace | Anything related to documentation label Nov 18, 2026
@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.50%. Comparing base (aed5e94) to head (40e2180).
⚠️ Report is 9 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #46339   +/-   ##
=======================================
  Coverage   85.50%   85.50%           
=======================================
  Files        3104     3104           
  Lines      214171   214183   +12     
  Branches    50585    50587    +2     
=======================================
+ Hits       183126   183139   +13     
+ Misses      27617    27616    -1     
  Partials     3428     3428           
Flag Coverage Δ
hive 33.99% <10.52%> (-0.01%) ⬇️
mysql 51.64% <10.52%> (-0.01%) ⬇️
postgres 51.67% <10.52%> (-0.01%) ⬇️
presto 35.69% <10.52%> (-0.01%) ⬇️
python 88.23% <100.00%> (+<0.01%) ⬆️
sqlite 51.35% <10.52%> (-0.01%) ⬇️
unit 83.44% <100.00%> (+<0.01%) ⬆️

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.

@mikebridge
mikebridge marked this pull request as ready for review November 19, 2026 00:18
Comment thread superset/semantic_layers/mapper.py Resolved
Comment thread superset/semantic_layers/mapper.py Resolved
@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; it ignores grains only for non-temporal fields without advertised variants and preserves existing variant handling.

Assessed commit: 40e2180560fa

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

Inapplicable grains are dropped consistently in validation and mapping.

Nit: A query-level grain on a text field with grain variants is still refused, as on master; untested.

Nit: test_categorical_legacy_grain_refuses_time_bounds docstring overstates: grainless bounds still hit the text field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc Namespace | Anything related to documentation size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants