Skip to content

fix: support inline reductions mixed with measure refs and deferred-join totals (#314) - #321

Open
mathisdrn wants to merge 1 commit into
boringdata:mainfrom
mathisdrn:fix/issue-314-calc-inline-reductions-deferred-totals
Open

mathisdrn wants to merge 1 commit into
boringdata:mainfrom
mathisdrn:fix/issue-314-calc-inline-reductions-deferred-totals

Conversation

@mathisdrn

Copy link
Copy Markdown

Fixes #314.

Problem

  1. Calculated measures that mix an inline reduction with a measure reference (e.g. lambda t: t.amount.sum() / t.n) raised IntegrityError because lift_inline_reductions did not rebind the virtual aggregate tables (vt_op, totals_vt_op) to include the lifted columns.
  2. t.all(...) totals on the deferred-join path (is_entity joins) raised TotalsNotAvailableError because _compile_deferred.py bypassed _compile_aggregation's windowed-totals handling and _find_deferrable_joins did not inspect calc measure dependencies / inline aggregates.

Fix

  • Rebind vt_op and totals_vt_op in lift_inline_reductions and thread lifted_calc_specs through attach_calc_totals in src/boring_semantic_layer/calc_compiler.py.
  • Pass known_measures | frozenset(lifted) and lifted_calc_specs in _compile_aggregation, inspect calc dependencies and inline aggregate callables in _find_deferrable_joins (src/boring_semantic_layer/ops/_core.py), and delegate deferred-join aggregation to _compile_aggregation (src/boring_semantic_layer/ops/_compile_deferred.py).
  • Add regression tests in src/boring_semantic_layer/tests/test_calc_compiler.py and src/boring_semantic_layer/tests/test_deferred_join.py.

Verification

  • ruff check . and ruff format --check . passed.
  • .venv/bin/pytest -q src/boring_semantic_layer/tests/test_calc_compiler.py src/boring_semantic_layer/tests/test_deferred_join.py src/boring_semantic_layer/tests/soundness/test_calc_window_totals.py src/boring_semantic_layer/tests/test_import_graph.py: 48 passed.

Note: This PR is AI-generated and human-reviewed.

This branch has not been deployed

No deployments
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.

Calc measure mixing an inline reduction with a measure reference raises IntegrityError

1 participant