fix(schema-compiler): handle sqlTable in originalSql pre-aggregation#10824
fix(schema-compiler): handle sqlTable in originalSql pre-aggregation#10824paveltiunov merged 2 commits intomasterfrom
Conversation
When a cube uses `sqlTable` instead of `sql`, the `preAggregationSql` method for `originalSql` type pre-aggregations would crash with: TypeError: Cannot read properties of undefined (reading 'apply') This happened because `cubeFromPath(cube).sql` is undefined for cubes that use `sqlTable`, and the undefined value was passed to `evaluateSql()` which called `resolveSymbolsCall(undefined, ...)`. The fix checks for `sqlTable` first (matching the logic in `cubeSql()`) before falling back to `sql`. Co-authored-by: Pavel Tiunov <pavel.tiunov@gmail.com>
|
Claude finished @paveltiunov's task in 1m 49s —— View job Code Review: PR #10824
Verdict: This PR looks good. The fix is correct, minimal, and well-tested. A few observations below. Fix Analysis (
|
d1a515c to
e4a57c6
Compare
|
Claude finished @paveltiunov's task in 1m 57s —— View job Code Review: PR #10824
Verdict: This PR looks good. The fix is correct, minimal, and well-tested. Detailed analysis below. Fix Analysis (
|
cfcd8f5 to
88f19a0
Compare
When a cube uses sqlTable instead of sql, the preAggregationSql method for originalSql type pre-aggregations crashed with: TypeError: Cannot read properties of undefined (reading 'apply') Root cause: cubeFromPath(cube).sql is undefined for cubes that use sqlTable, and the undefined value was passed to evaluateSql() which called resolveSymbolsCall(undefined, ...). The fix handles the sqlTable case separately, wrapping the resolved table name in SELECT * FROM to produce valid SQL (matching the semantics of cubeSql()). Also adds an integration test that runs the pre-aggregation query against Postgres via evaluateQueryWithPreAggregations(). Co-authored-by: Pavel Tiunov <pavel.tiunov@gmail.com>
88f19a0 to
1237bb5
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #10824 +/- ##
==========================================
+ Coverage 58.09% 58.16% +0.06%
==========================================
Files 216 216
Lines 16899 16942 +43
Branches 3426 3436 +10
==========================================
+ Hits 9818 9854 +36
- Misses 6578 6585 +7
Partials 503 503
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:
|
Check List
Description of Changes Made
When a cube uses
sqlTableinstead ofsql, thepreAggregationSqlmethod fororiginalSqltype pre-aggregations crashes with:This happens during
/cubejs-system/v1/pre-aggregations/partitionscalls when the cube definition usessqlTableinstead ofsql.Root cause: In
BaseQuery.preAggregationSql(), theoriginalSqlbranch calledevaluateSql(cube, cubeFromPath.sql)directly, butcubeFromPath.sqlisundefinedfor cubes that usesqlTable.Fix: For the
sqlTablecase, reuse the existingcubeSql()method (which already handlessqlTablecorrectly) to resolve the table name and wrap it inSELECT * FROM. For thesqlcase, keep the existingevaluateSql()call unchanged:Tests added:
originalSqlpre-aggregations on cubes that usesqlTable, verifyingpreAggregationSql()produces validSELECT * FROMSQL.dbRunner.evaluateQueryWithPreAggregations(), verifying correct data retrieval through theoriginalSqlpre-aggregation withsqlTable.