Skip to content

Commit

Permalink
fix: Pre-aggregations should have default refreshKey of every 1 hour …
Browse files Browse the repository at this point in the history
…if it doesn't set for Cube (#3259)
  • Loading branch information
paveltiunov committed Aug 16, 2021
1 parent 73d6778 commit bc472aa
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 53 deletions.
21 changes: 1 addition & 20 deletions packages/cubejs-schema-compiler/src/adapter/BaseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -2251,7 +2251,6 @@ export class BaseQuery {
}

if (
preAggregation.partitionGranularity &&
!preAggregationQueryForSql.allCubeNames.find(c => {
const fromPath = this.cubeEvaluator.cubeFromPath(c);
return fromPath.refreshKey && fromPath.refreshKey.sql;
Expand All @@ -2261,25 +2260,7 @@ export class BaseQuery {
return preAggregationQueryForSql.evaluateSymbolSqlWithContext(
() => preAggregationQueryForSql.cacheKeyQueries(
(refreshKeyCube, [refreshKeySQL, refreshKeyQueryOptions, refreshKeyQuery]) => {
if (cubeFromPath.refreshKey && cubeFromPath.refreshKey.immutable) {
/**
* It's not supported in Cube Store, because it doesnt support Sub Query
* There is a PR with fix for that https://github.com/cube-js/cube.js/pull/3098
* But probably we will remove immutable refreshKeys in the future
*/
return [
this.refreshKeySelect(
this.incrementalRefreshKey(preAggregationQueryForSql, `(${refreshKeySQL})`, {
refreshKeyQuery
})
),
{
external: refreshKeyQueryOptions.external,
renewalThreshold: this.defaultRefreshKeyRenewalThreshold(),
},
refreshKeyQuery
];
} else if (!cubeFromPath.refreshKey) {
if (!cubeFromPath.refreshKey) {
const [sql, external, query] = this.everyRefreshKeySql({
every: '1 hour'
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,8 @@ describe('PreAggregations', () => {

const queries = dbRunner.tempTablePreAggregations(preAggregationsDescription);

expect(queries.filter(([q]) => !!q.match(/3600/)).length).toBeGreaterThanOrEqual(1);

console.log(JSON.stringify(queries.concat(queryAndParams)));

return dbRunner.evaluateQueryWithPreAggregations(query).then(res => {
Expand Down Expand Up @@ -1266,6 +1268,8 @@ describe('PreAggregations', () => {

const queries = dbRunner.tempTablePreAggregations(preAggregationsDescription);

expect(queries.filter(([q]) => !!q.match(/3600/)).length).toBeGreaterThanOrEqual(1);

console.log(JSON.stringify(queries.concat(queryAndParams)));

return dbRunner.evaluateQueryWithPreAggregations(query).then(res => {
Expand Down
33 changes: 0 additions & 33 deletions packages/cubejs-schema-compiler/test/unit/base-query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,39 +383,6 @@ describe('SQL Generation', () => {
`
})
);

it('refreshKey from cube immutable (external)', async () => {
await compiler.compile();

const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, {
measures: [
'cards.count'
],
timeDimensions: [{
dimension: 'cards.createdAt',
granularity: 'day',
dateRange: ['2016-12-30', '2017-01-05']
}],
filters: [],
timezone: 'America/Los_Angeles',
externalQueryClass: MssqlQuery
});

const preAggregations: any = query.newPreAggregations().preAggregationsDescription();
expect(preAggregations.length).toEqual(1);
expect(preAggregations[0].invalidateKeyQueries).toEqual([
[
'SELECT CASE\n WHEN CURRENT_TIMESTAMP < CAST($1 AS DATETIME2) THEN (SELECT FLOOR((DATEDIFF(SECOND,\'1970-01-01\', GETUTCDATE())) / 10) as refresh_key) END as refresh_key',
[
'__TO_PARTITION_RANGE'
],
{
external: true,
renewalThreshold: 10,
}
]
]);
});
});

describe('refreshKey only cube (every)', () => {
Expand Down

0 comments on commit bc472aa

Please sign in to comment.