fix limited-distinct identity contract#2174
Merged
Merged
Conversation
✅ Deploy Preview for thriving-cassata-78ae72 canceled.
|
shangyian
added a commit
that referenced
this pull request
May 25, 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.
Summary
A metric defined as
COUNT(DISTINCT id)carries a derived expression likecount(DISTINCT id_distinct_HASH)(it references the hashed component identity). However, the measures SQL output for that metric projects only the bareidcolumn, so external consumers using the derived expression to evaluate against the measures output can't resolve the column.PR #1931 introduced a
grain_aliasfield onMetricComponent: for plain-columnDISTINCTit was set to the bare column name, for complexDISTINCT(e.g.,CASE/IFexpressions) it stayed equal to the component name (hashed). The measures sql then routed plain-DISTINCT projections undergrain_aliasas an optimization, with the idea being that the bare column is already in the projection as aGROUP BYgrain key, so there was no need to emit a redundant aliased copy.To fix this, we add the
register_limited_componenthelper function:DISTINCT, it emits an extra<bare> AS <component.name>projection so that the combiner rewriters stay consistent.DISTINCT, the behavior is unchanged.This also adds backwards-compatibility for materializations created before the fix.
Test Plan
make checkpassesmake testshows 100% unit test coverageDeployment Plan