Skip to content

Commit

Permalink
feat: updateWindow property for incremental partitioned rollup refr…
Browse files Browse the repository at this point in the history
…eshKey
  • Loading branch information
paveltiunov committed Jan 21, 2020
1 parent 6242b36 commit 09c0a86
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
12 changes: 9 additions & 3 deletions packages/cubejs-schema-compiler/adapter/BaseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -1479,15 +1479,17 @@ class BaseQuery {
return `FLOOR(${numeric})`;
}

incrementalRefreshKey(query, originalRefreshKey) {
incrementalRefreshKey(query, originalRefreshKey, options) {
options = options || {};
const updateWindow = options.window;
return query.evaluateSql(
null,
(FILTER_PARAMS) => query.caseWhenStatement([{
sql: FILTER_PARAMS[
query.timeDimensions[0].path()[0]
][
query.timeDimensions[0].path()[1]
].filter((from, to) => `${query.nowTimestampSql()} < ${this.timeStampCast(to)}`),
].filter((from, to) => `${query.nowTimestampSql()} < ${updateWindow ? this.addInterval(this.timeStampCast(to), updateWindow) : this.timeStampCast(to)}`),
label: originalRefreshKey
}])
);
Expand All @@ -1514,7 +1516,11 @@ class BaseQuery {
if (!preAggregation.partitionGranularity) {
throw new UserError(`Incremental refresh key can only be used for partitioned pre-aggregations`);
}
refreshKey = this.incrementalRefreshKey(preAggregationQueryForSql, refreshKey);
refreshKey = this.incrementalRefreshKey(
preAggregationQueryForSql,
refreshKey,
{ window: preAggregation.refreshKey.updateWindow }
);
}
if (preAggregation.refreshKey.every || preAggregation.refreshKey.incremental) {
return {
Expand Down
3 changes: 2 additions & 1 deletion packages/cubejs-schema-compiler/compiler/CubeValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ const BasePreAggregation = {
}),
Joi.object().keys({
every: everyInterval,
incremental: Joi.boolean()
incremental: Joi.boolean(),
updateWindow: timeInterval
})
),
useOriginalSqlPreAggregations: Joi.boolean(),
Expand Down
3 changes: 2 additions & 1 deletion packages/cubejs-schema-compiler/test/PreAggregationsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ describe('PreAggregations', function test() {
partitionGranularity: 'month',
refreshKey: {
every: '1 hour',
incremental: true
incremental: true,
updateWindow: '1 day'
}
}
}
Expand Down

0 comments on commit 09c0a86

Please sign in to comment.