fix(tesseract): widen pre-aggregation range for time_shift reads through a view - #11554
Draft
hamid025 wants to merge 1 commit into
Draft
fix(tesseract): widen pre-aggregation range for time_shift reads through a view#11554hamid025 wants to merge 1 commit into
hamid025 wants to merge 1 commit into
Conversation
…ugh a view `extract_date_range` widens the matched partition range backwards by the shift interval so a shifted leaf can reach its rows. The lookup that finds the interval used `BaseFilter::member_name()`, which is `member_evaluator().full_name()` and only peels the `TimeDimension` wrapper — it never walks the reference chain. `dimensions_shifts`, however, is keyed by reference-chain-resolved names: `all_time_members` calls `resolve_reference_chain()` on every symbol before it becomes a key. A view member is a reference to the underlying cube member, so its unresolved name never equals the key, the lookup missed, and the range was left unwidened for view-qualified queries. The shifted leaf then scanned a partition set that could not contain its rows and yielded NULL — silently, with no error — while the identical cube-qualified query returned correct values. Views are the recommended query interface for BI tools, so most consumer queries take the broken path, and shorter windows are affected worst: for an interval I over a range of N days, only the last N-I days get values. Retry the lookup with the resolved name. A member resolving to a different cube's dimension still does not match, so this cannot apply a shift that would not otherwise apply. Fixes cube-js#11536 Signed-off-by: Abdulkhamid Ibragimov <abdulkhamid.ibragimov@careem.com>
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.
Fixes #11536.
Problem
A
multi_stagemeasure with atime_shiftreturns NULL when queried through a view, if the query's date range does not itself already contain the shifted period. The identical query against the cube returns correct values.extract_date_rangewidens the matched partition range backwards by the shift interval so the shifted leaf can reach its rows. That widening is skipped for view-qualified queries, so the leaf scans a partition set that cannot contain its rows and yields NULL — silently, with no error.The pre-aggregation description shows it directly — same query, only the namespace differs:
matchedTimeDimensionDateRange2026-08-03 … 2026-08-09— not widened2026-07-27 … 2026-08-09— widened by exactly the 7-day shiftRoot cause
The interval lookup uses
BaseFilter::member_name(), which ismember_evaluator().full_name().member_evaluator()calls onlyresolve_base_symbol— it peels theTimeDimensionwrapper but never walks the reference chain.dimensions_shiftsis keyed by reference-chain-resolved names:all_time_memberscallsresolve_reference_chain()on every symbol before it becomes a key (planner/query_properties.rs).A view member is a reference to the underlying cube member, so its unresolved name never equals the resolved key, the lookup misses, and no shift is applied.
Fix
Resolve the chain and retry — an exact second lookup, using the identity mechanism already used elsewhere. A member resolving to a different cube's dimension still does not match, so this cannot apply a shift that would not otherwise apply.
Fixing at the insert site instead looks worse:
dimensions_shiftsis also consumed byextract_time_shiftsfor render-time SQL, so re-keying there would change rendering as well.Test
pre-aggregations-multi-stage-time-shift-view.test.tscovers both the direct signal and the end-to-end result:matchedTimeDimensionDateRangemust equal the cube query'snullbefore the fix)Gated on
getEnv('nativeSqlPlanner'), consistent with the other Tesseract pre-aggregation tests.Impact
Views are the recommended query interface for BI tools, so in practice most consumer queries take the broken path. The failure is silent: a week-over-week column renders blank and is indistinguishable from genuinely absent data. Shorter windows are affected worst — for an interval
Iand a range ofNdays, only the lastN − Idays get values, so a "last 7 days" dashboard with a 7-day shift is entirely blank.Notes
Opened as a draft: the change is verified against the source (all three APIs it relies on are present with the expected signatures) but I have no local Rust/Postgres toolchain, so neither the build nor the new test has been run on my side. Marking ready once CI confirms. Happy to adjust the test's fixture dates if the rollup does not match as written.