Skip to content

Fix cube materialization for cubes with derived metrics#2220

Merged
shangyian merged 5 commits into
DataJunction:mainfrom
shangyian:fix-cube-mat-error
Jun 4, 2026
Merged

Fix cube materialization for cubes with derived metrics#2220
shangyian merged 5 commits into
DataJunction:mainfrom
shangyian:fix-cube-mat-error

Conversation

@shangyian
Copy link
Copy Markdown
Collaborator

@shangyian shangyian commented Jun 4, 2026

Summary

Cubes containing derived ratio metrics failed with 'NoneType' object is not subscriptable because those metrics weren't being returned by the v3 measures-SQL builder.

The fix is to register derived metrics on their grain group. The v3 builder tracks derived metrics in BuildContext.decomposed_metrics but doesn't list them in any GrainGroupSQL.metrics. The v2-shape adapter
_v3_grain_group_to_measures_query now also walks decomposed_metrics and registers any derived metric whose components are fully covered by this grain group's components, so downstream build_cube_materialization can emit a CubeMetric for it.

Also added a defensive error for missing-metric-mapping. If a cube metric isn't in the built metrics_mapping, raise a descriptive DJInvalidInputException naming the missing metric(s) instead of crashing with NoneType is not subscriptable deeper in the comprehension.

Test Plan

  • PR has an associated issue: #
  • make check passes
  • make test shows 100% unit test coverage

Deployment Plan

@netlify
Copy link
Copy Markdown

netlify Bot commented Jun 4, 2026

Deploy Preview for thriving-cassata-78ae72 canceled.

Name Link
🔨 Latest commit 4e71675
🔍 Latest deploy log https://app.netlify.com/projects/thriving-cassata-78ae72/deploys/6a2130738be51b0008645b36

@shangyian shangyian force-pushed the fix-cube-mat-error branch from bc91260 to e35293e Compare June 4, 2026 07:55
@shangyian shangyian changed the title Fix cube mat error Fix cube materialization for cubes with derived metrics Jun 4, 2026
@shangyian shangyian marked this pull request as ready for review June 4, 2026 08:24
@shangyian shangyian merged commit e7f6dc0 into DataJunction:main Jun 4, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant