fix(tesseract): pre-aggregation table name corruption when one name is a prefix of another#11000
Conversation
…s a prefix of another
|
Claude finished @waralexrom's task in 59s —— View job Code ReviewVerdict: LGTM — correct fix for a real, deterministic bug. 0 high, 0 medium, 2 low. DetailsTasks
CorrectnessThe diagnosis is right.
Both orderings break, so length-sorting alone wouldn't have been enough — single-pass replacement is the right fix. Implementation (
|
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## master #11000 +/- ##
===========================================
- Coverage 83.32% 58.54% -24.78%
===========================================
Files 255 216 -39
Lines 77177 17157 -60020
Branches 0 3495 +3495
===========================================
- Hits 64304 10044 -54260
+ Misses 12873 6606 -6267
- Partials 0 507 +507
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
QueryCache.replacePreAggregationTableNamesreplaced pre-aggregation placeholder table names sequentially with a global string replace per entry, which corrupts the SQL when one placeholder name is a prefix of another. With per-usage partition pruning (Tesseract), entries are suffixedname0..name10..., so 11+ usages of the same rollup in one query deterministically produce broken SQL like(SELECT ...)0 AS "alias"and fail on CubeStore withParserError("Expected: ), found: 0").Sequential replacement is broken in any order: real target names are built as
tableName + '_' + versions(seePreAggregations.targetTableName), so a source name also matches inside already inserted target names of other entries.Changes
Map-based replacement callback — inserted text is never rescannedQueryWithParamspassthrough, empty replacements, literal$in target names, input array immutabilityTesting
yarn jest test/unit/ReplacePreAggregationTableNames.test.ts— 7 passed; the two collision tests fail against the previous implementationCUBEJS_TESSERACT_SQL_PLANNER=true,CUBEJS_TESSERACT_PRE_AGGREGATIONS=true) on a query with 10+ multi-stage measures from one view (11 usages of the same rollup); fix verified against that setup