Skip to content

fix(compiler): dedup fanned-out additive leaves in composite metrics - #251

Merged
mischuh merged 1 commit into
mainfrom
fix/ratio-metric-fanout-inflation
Jul 28, 2026
Merged

fix(compiler): dedup fanned-out additive leaves in composite metrics#251
mischuh merged 1 commit into
mainfrom
fix/ratio-metric-fanout-inflation

Conversation

@mischuh

@mischuh mischuh commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • Ratio/weighted_avg metrics (composite.py) skipped the fanout-safe DISTINCT ON dedup for additive leaves that need a one_to_many/many_to_many join to reach the requested dimension, silently inflating the numerator/denominator (reported via a jaffle_shop avg_revenue_per_unit_sold query grouped by product.name).
  • _build_deduped moved from simple_additive.py to the shared _helpers.py and reused in composite.py::_plan_leaf's additive+fanout branch, mirroring the existing simple-additive fanout protection.
  • Added measure_aliases param so a composite leaf can alias its aggregate to n/d instead of the measure's own name.

Test plan

  • pytest tests/compiler/test_composable.py — new SQL-structure + executed-DuckDB numeric-correctness regression tests
  • pytest tests/ — full suite green
  • ruff check . && ruff format --check . / mypy canonic/
  • Manually verified against the reporting user's jaffle_shop project — avg_revenue_per_unit_sold now matches revenue / units_sold exactly

🤖 Generated with Claude Code

- Reuse the existing DISTINCT ON fanout-safe dedup (_build_deduped,
  moved to _helpers.py) in composite.py's ratio/weighted_avg leaf
  planning, which previously skipped it for additive measures
- Add measure_aliases param so leaves alias to n/d instead of the
  measure's own name
- Add regression tests: SQL structure + executed DuckDB numeric check
@mischuh mischuh self-assigned this Jul 28, 2026
@mischuh
mischuh merged commit 51e424a into main Jul 28, 2026
5 checks passed
@mischuh
mischuh deleted the fix/ratio-metric-fanout-inflation branch July 28, 2026 09:32
@mischuh mischuh mentioned this pull request Jul 28, 2026
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