Skip to content

Conversation

@shangyian
Copy link
Contributor

@shangyian shangyian commented Jan 4, 2026

Summary

Shared Dimensions for Derived Metrics

When querying derived metrics, the system needed to correctly compute which dimensions are available. A derived metric that references multiple base metrics should be able to use dimensions from any of its base metrics (union), while multiple metrics queried together should only expose shared dimensions (intersection).

The changes modified get_shared_dimensions() to compute per-metric dimension unions first, then intersect across metrics. We also add get_metric_parents_map() to batch-fetch parent mappings while maintaining metric-to-parent relationships. This enables dimension determination for derived metrics to work correctly.

AST Column Compilation for Derived Metrics

Derived metric queries have no FROM clause - they reference base metrics directly as columns (e.g., SELECT default.revenue / default.orders). The AST compiler couldn't resolve these references with the right types.

The changes here extended Column.compile() to resolve metric references by looking up the metric node and getting its output type, and added support for dimension attribute references for ordering/filtering.

Pre-expanded Template Handling

Metric decomposition could produce pre-expanded aggregation templates like SUM(POWER(match_score, 2)) instead of the unexpanded SUM(POWER({}, 2)). The build_component_expression() function didn't handle these. This change adds detection for pre-expanded templates, which are parsed directly as complete SQL expressions.

Test Plan

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

Deployment Plan

@netlify
Copy link

netlify bot commented Jan 4, 2026

Deploy Preview for thriving-cassata-78ae72 canceled.

Name Link
🔨 Latest commit 5182124
🔍 Latest deploy log https://app.netlify.com/projects/thriving-cassata-78ae72/deploys/695a0d3c55abca0008129f92

@shangyian shangyian changed the title Derived metrics UI Derived Metrics Bugs Jan 4, 2026
@shangyian shangyian marked this pull request as ready for review January 4, 2026 07:09
@shangyian shangyian merged commit cdaa5c7 into DataJunction:main Jan 4, 2026
17 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