Repository navigation
Conversation
A calc measure that reads a joined model's measure, e.g. `t.revenue / t["customers.n"]` on orders join_one customers, was routed by its own (root-owned) name onto the flattened-join path, so `customers.n` was counted over fanned-out order rows. Requesting the calc alone returned a silently wrong answer; requesting it alongside its dependencies went through source pre-aggregation and was correct. Route on the transitive dependencies of requested calc measures too. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
`from_config` attaches calculated_measures before joins, so an expression such as `_.revenue / _['customers.n']` could not be analyzed at definition time. Classification then demoted it to a base measure, which ran against the raw table at query time and raised DefinitionError. YAML calculated_measures are measure expressions by contract, so keep them as calc measures marked `unresolved` instead; the aggregation plan recovers their dependencies against the joined scope, and the router sends them through source pre-aggregation so they cannot fan out. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Problem
A YAML
calculated_measuresentry that reads a joined model's measure fails at query time withDefinitionError:Ratios over the model's own measures already work on a joined model; only cross-model references fail.
While fixing this, I found a silent wrong-answer bug in the Python API that the YAML fix would otherwise have exposed.
with_measures(ratio=lambda t: t.revenue / t["customers.n"])on ajoin_onereturns a fanned-out result whenratiois requested alone, but the correct result when it's requested alongside its dependencies.Changes
Two commits. The first stands on its own and can be split into a separate PR if you prefer.
Route calc measures by their dependencies.
SemanticAggregateOp.to_untaggedchose between the source pre-aggregation path and the flattened-join path by looking only at the requested measure names. A calc measure owned by the root but readingcustomers.ntook the flattened path, wherecustomers.ngets counted over order rows. Routing now also considers the transitive dependencies of requested calc measures.Allow YAML calculated measures to read joined models.
from_configattachescalculated_measuresbefore joins, so_['customers.n']can't be evaluated at definition time._classify_measurethen demoted the expression to a base measure, which ran against the raw table at query time. YAML calculated measures are measure expressions by contract (__bsl_prefer_known__). They now stay calc measures markedCalcMeasure.unresolved; the aggregation plan recovers their dependencies against the joined scope, and the router sends unresolved calcs through pre-aggregation.I kept the attach-before-join order on purpose. Attaching after the join would rename the measure:
orders.revenue_per_customerwould no longer resolve.Tests
test_bi_traps.py::TestCalcOverJoinedMeasure: the Python API calc gives the same answer requested alone as with its dependencies (150 / 2, not 150 / 5).test_yaml.py::test_yaml_calculated_measures_over_joined_model: both bracket spellings, ungrouped and grouped by a dimension.All 4 new tests fail on
main. Full suite: 1074 passed, which is the 1070 baseline plus these 4, with the same skipped/xfail/xpass counts.Not addressed
_.customers.nstill fails, in the Python API too (UnknownMeasureRefError: 'customers' is not a known measure or column). Only_['customers.n']works.serialization/extract.py) rebuildsCalcMeasurewithoutunresolved, just as it already dropsprefer_known. YAML calc closures don't appear to be serializable throughexpr_structanyway.🤖 Generated with Claude Code