Add partition filter pushdown for more efficient rolling windows#1854
Draft
shangyian wants to merge 3 commits intoDataJunction:mainfrom
Draft
Add partition filter pushdown for more efficient rolling windows#1854shangyian wants to merge 3 commits intoDataJunction:mainfrom
shangyian wants to merge 3 commits intoDataJunction:mainfrom
Conversation
✅ Deploy Preview for thriving-cassata-78ae72 canceled.
|
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 improves the efficiency of generated SQL by pushing down temporal filters from the outer query into the upstream driving CTE, rather than applying them after the full query has been evaluated.
Previously, when
include_temporal_filters=Truewas requested, DJ would inject theDJ_LOGICAL_TIMESTAMP()filter as a WHERE clause on the outermost grain-group query. For simple fact table queries this is fine, but for transforms that use a date spine to drive a range join (e.g. rolling window metrics), the filter arrived too late, and the entire join had already been evaluated across all dates before a single row was selected.With this change, DJ detects when the parent transform's primary FROM table is itself an upstream transform that exposes the temporal FK column. In that case, the filter is injected directly into that upstream CTE's WHERE clause instead, so the join only runs for the target partition(s). If no eligible upstream transform is found (e.g. the parent reads directly from a source table), the behavior falls back to the original outer WHERE approach unchanged.
This is particularly important for rolling window patterns, where a date spine drives a range join against a large fact table. Filtering the date spine to the target date before the join means the fact table is only scanned for the rows that are actually needed, rather than for every date in history.
Test Plan
make checkpassesmake testshows 100% unit test coverageDeployment Plan