feat: semi-additive measures - #2502
Merged
Merged
Conversation
✅ Deploy Preview for thriving-cassata-78ae72 canceled.
|
betodealmeida
force-pushed
the
semi-additive-metrics
branch
3 times, most recently
from
September 4, 2026 21:13
733896b to
17e0ca9
Compare
betodealmeida
marked this pull request as ready for review
September 10, 2026 14:20
shangyian
self-requested a review
September 14, 2026 16:56
shangyian
reviewed
Sep 14, 2026
robinld
reviewed
Sep 18, 2026
robinld
reviewed
Sep 18, 2026
betodealmeida
force-pushed
the
semi-additive-metrics
branch
from
September 22, 2026 18:10
76a7dc0 to
ed0937a
Compare
3 tasks
betodealmeida
force-pushed
the
semi-additive-metrics
branch
from
September 23, 2026 14:03
57ddf78 to
1f22459
Compare
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.
Summary
This PR adds metric reaggregation support for semi-additive measures, aligned with the proposal #2245. Metrics can declare protected dimensions, and the aggregation behavior changes when the query grain drops the dimension.
For example, suppose we have this metric:
Meaning:
If we get a request that includes the protected dimension:
We generate this SQL:
Because
date_id_orderis still in the output grain, there is no semi-additive collapse. Normal aggregation is safe.On the other hand, if we don't request the protected dimension we shouldn't aggregate over it:
The generated SQL:
Here, the user asked for
category only, but DJ keepsdate_id_orderas a private inner grain. Then it collapses each category’s daily balances withMAX_BY(value, date), meaning "take the value from the latest date."Without this, DJ would generate something like:
That would incorrectly sum balances across dates, which is wrong for snapshots or balances, for example.
I've updated the UI to show and allow setting the semi-additive dimension:
When editing:
Valid options:
Test Plan
make checkpassesmake testshows 100% unit test coverageDeployment Plan