Repository navigation
fix: let measures read derived dimensions outside the group-by (#310) - #311
Merged
Merged
Conversation
Query compilation only materialized the group-by keys, so a measure over a derived dimension (total_revenue = t.revenue.sum()) raised AttributeError whenever the query grouped by something else or not at all. Materialize the derived dimensions each requested measure reads, on the single-table, joined and join_many pre-aggregation paths. with_measures() also classified lambdas against the raw table, so a derived dimension named close to a column (url_s vs url) was reported as a typo. Classify against the table enriched with derived dimensions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- with_measures: don't add a dimension named like a measure to the classification table; calc scopes resolve columns first, so it hid the measure and turned calc measures into base ones. - Resolve the bare dimension name a measure reads against the measure's own model first, so a same-named dimension on another joined model no longer blocks it. - Apply the same materialization on the deferred-join path. - Probe calc measures too, so inline reductions over derived dimensions (t.revenue.sum() / t.all(t.revenue.sum())) resolve. - Stop retrying when materializing makes no progress (dotted dimension names used to loop forever). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- with_measures: also skip dimensions whose dependency chain would add a column named like a measure. - On joins, alias the owning model's dimensions under their bare names (owner taken from the measure's prefix, or from its unique qualified name when requested by short name), so the model wins over a same-named dimension elsewhere, through dependency chains too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- When a measure reads its own model's dimension through a name that is a raw column of another joined model, raise a clear error instead of silently reading the other model's column. - Never materialize a measure-named column at query time, including through a dimension's dependencies. - Materialize derived dimensions for measures defined on the join itself (pre-aggregation wrapper path). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Four review rounds showed that bare-name dimension resolution on joined models has edge cases beyond #310 (ownership, foreign columns, wrapper measures). Restore main's behaviour for joins and keep the fix to the single-model query and with_measures paths that the issue reports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
as_table() flattens a SemanticJoin into a plain model without _source_join, so the single-model guard let derived-dimension materialization run on a joined table and read another model's raw column. Treat any model whose relation contains a join as joined. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #310 for single models. Derived-dimension measures on joined models are tracked separately (see the scope note below).
Problem
On a single model, a measure over a derived dimension crashed unless the query also grouped by that dimension:
with_measures()also checked measure lambdas against the raw table, so a derived dimension named close to a column (url_svsurl) could be reported as a typo.Fix
SemanticAggregateOp.to_untagged(), single-model path only: after the aggregation plan is built,_mutate_measure_dimension_depsprobes each requested base measure and calc measure. When one reads a derived dimension the table lacks, that dimension and its dependencies are materialized. This also covers inline reductions inside calc measures (t.revenue.sum() / t.all(t.revenue.sum())).SemanticModel.with_measures(), single models only: measures are classified against the table with derived dimensions added (best-effort, never overwriting existing columns).Scope note: joins are unchanged
Four rounds of independent review found that bare-name dimension resolution on joined models has its own problems: the owning model vs a same-named dimension or raw column on another model, wrapper measures, and dependency chains. The early versions of this PR got some of those wrong, including silently wrong numbers in one case. So join paths (
_compile_preagg,_compile_deferred, and the join branch ofto_untagged) behave exactly as onmain. Separately, #314 tracks a calc measure mixing an inline reduction with a measure reference, which fails onmaineven with raw columns.Two more notes on joins:
join.as_table()and models built on a raw ibis join) is also treated as joined.main: fourjoin_manyinline-calc cases that already fail onmainnow raiseValueErrorinstead ofAttributeError, because leaf-model classification changed. No successful result changes.Independent review: 6 rounds with gpt-6-astra; round 6 approved. Join compiler files are byte-identical to
main, and 77 paired join cases were compared againstmain.Tests
tests/test_measure_derived_dimensions.pyhas 12 single-model cases: grouped by another dimension, ungrouped, chained derived dimensions, calc measure on top, inline-reduction calc, filter,query()API, theurl_snear-name case, a measure and a dimension with the same name (direct and through a dependency, at definition and at query time), and termination on dotted names.test_chart_png_format_plotly, which needs headless Chrome (missing on the dev VM; passes in CI).🤖 Generated with Claude Code