Skip to content

Commit f4ee7b6

Browse files
committed
fix: originalSql pre-aggregations with FILTER_PARAMS params mismatch
fix: Re-use default refreshKey only if cube's refreshKey not overridden
1 parent f2000c0 commit f4ee7b6

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

packages/cubejs-schema-compiler/adapter/BaseQuery.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ class BaseQuery {
14181418
return [
14191419
this.evaluateSymbolSqlWithContext(
14201420
() => this.evaluateSql(cube, this.cubeEvaluator.cubeFromPath(cube).sql),
1421-
{ preAggregationQuery: true }
1421+
{ preAggregationQuery: true, originalSqlPreAggregation: true }
14221422
),
14231423
[]
14241424
];
@@ -1438,14 +1438,18 @@ class BaseQuery {
14381438

14391439
preAggregationInvalidateKeyQueries(cube, preAggregation) {
14401440
const preAggregationQueryForSql = this.preAggregationQueryForSqlEvaluation(cube, preAggregation);
1441-
if (preAggregation.refreshKey) {
1442-
if (preAggregation.refreshKey.sql) {
1443-
return [this.paramAllocator.buildSqlAndParams(
1444-
preAggregationQueryForSql.evaluateSql(cube, preAggregation.refreshKey.sql)
1445-
)];
1446-
}
1441+
if (preAggregation.refreshKey && preAggregation.refreshKey.sql) {
1442+
return [this.paramAllocator.buildSqlAndParams(
1443+
preAggregationQueryForSql.evaluateSql(cube, preAggregation.refreshKey.sql)
1444+
)];
14471445
}
1448-
if (preAggregation.partitionGranularity) {
1446+
if (
1447+
preAggregation.partitionGranularity &&
1448+
!preAggregationQueryForSql.collectCubeNames().find(c => {
1449+
const fromPath = this.cubeEvaluator.cubeFromPath(c);
1450+
return fromPath.refreshKey && fromPath.refreshKey.sql;
1451+
})
1452+
) {
14491453
const cubeFromPath = this.cubeEvaluator.cubeFromPath(cube);
14501454
return preAggregationQueryForSql.evaluateSymbolSqlWithContext(
14511455
() => preAggregationQueryForSql.cacheKeyQueries(
@@ -1549,7 +1553,12 @@ class BaseQuery {
15491553
allFilters.find(f => f.dimension === this.cubeEvaluator.pathFromArray([cubeNameObj.cube, propertyName]));
15501554
return {
15511555
filter: (column) => {
1552-
if (filter && filter.filterParams() && filter.filterParams().length) {
1556+
if (
1557+
filter &&
1558+
filter.filterParams() &&
1559+
filter.filterParams().length &&
1560+
!this.safeEvaluateSymbolContext().originalSqlPreAggregation
1561+
) {
15531562
if (typeof column === "function") {
15541563
return column.apply(
15551564
null,

packages/cubejs-schema-compiler/test/PreAggregationsTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('PreAggregations', function test() {
1919
const { compiler, joinGraph, cubeEvaluator } = prepareCompiler(`
2020
cube(\`visitors\`, {
2121
sql: \`
22-
select * from visitors
22+
select * from visitors WHERE \${FILTER_PARAMS.visitors.createdAt.filter('created_at')}
2323
\`,
2424
2525
joins: {

0 commit comments

Comments
 (0)