v3 SQL: walk every source-table reference when pushing dim filters#2166
Merged
Conversation
✅ Deploy Preview for thriving-cassata-78ae72 canceled.
|
3 tasks
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
Direct dim-link pushdown in v3 only injects the filter into the primary select of a transform's source body. When the same source table is referenced multiple times (e.g., a pattern where the inner subquery rejoins the source for an FK lookup), the secondary reference is left unfiltered.
There are two pushdown paths in v3:
dimensions.py's_register_pushdown_into_upstream): runs when the filter resolves via an upstream link rather than a direct one. Uses_resolve_pushdown_targets, which searches through the entire parsed source body and injects into every reference's enclosing select.cte.py's_resolve_pushdown_filters_for_cte): runs when the parent transform has a direct dim link. Only looks at the CTE's primary select projection and injects into its where clause. Doesn't walk nested subqueries.Counter-intuitively, adding a direct dim link to a transform makes pushdown less thorough because it short-circuits the upstream path that does the full walk. Modelers see the regression appear when they add what they think is a more-specific link.
The fix is to extend the direct path in
cte.pyto do the samefind_all(ast.Table)walk that the indirect path does. After the primary-select rewrite succeeds.Test Plan
make checkpassesmake testshows 100% unit test coverageDeployment Plan