Skip to content

Commit e4d2874

Browse files
committed
feat: refreshRangeStart and refreshRangeEnd pre-aggregation params
1 parent b7afa7a commit e4d2874

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,8 +1888,14 @@ class BaseQuery {
18881888
const timeDimension = this.newTimeDimension(references.timeDimensions[0]);
18891889

18901890
return this.evaluateSymbolSqlWithContext(() => [
1891-
this.paramAllocator.buildSqlAndParams(this.aggSelectForDimension(timeDimension.path()[0], timeDimension, 'min')),
1892-
this.paramAllocator.buildSqlAndParams(this.aggSelectForDimension(timeDimension.path()[0], timeDimension, 'max'))
1891+
this.paramAllocator.buildSqlAndParams(
1892+
preAggregation.refreshRangeStart && this.evaluateSql(cube, preAggregation.refreshRangeStart.sql) ||
1893+
this.aggSelectForDimension(timeDimension.path()[0], timeDimension, 'min')
1894+
),
1895+
this.paramAllocator.buildSqlAndParams(
1896+
preAggregation.refreshRangeEnd && this.evaluateSql(cube, preAggregation.refreshRangeEnd.sql) ||
1897+
this.aggSelectForDimension(timeDimension.path()[0], timeDimension, 'max')
1898+
)
18931899
], { preAggregationQuery: true });
18941900
}
18951901

packages/cubejs-schema-compiler/compiler/CubeValidator.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ const BasePreAggregation = {
7878
external: Joi.boolean(),
7979
partitionGranularity: Joi.any().valid('hour', 'day', 'week', 'month', 'year'),
8080
scheduledRefresh: Joi.boolean(),
81+
refreshRangeStart: {
82+
sql: Joi.func().required()
83+
},
84+
refreshRangeEnd: {
85+
sql: Joi.func().required()
86+
},
8187
indexes: Joi.object().pattern(identifierRegex, Joi.alternatives().try(
8288
Joi.object().keys({
8389
sql: Joi.func().required()

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ describe('PreAggregations', function test() {
196196
granularity: 'day',
197197
partitionGranularity: 'month',
198198
scheduledRefresh: true,
199+
refreshRangeStart: {
200+
sql: "SELECT NOW() - interval '30 day'"
201+
},
199202
refreshKey: {
200203
every: '1 hour',
201204
incremental: true,
@@ -523,6 +526,8 @@ describe('PreAggregations', function test() {
523526

524527
console.log(minMaxQueries);
525528

529+
minMaxQueries[0][0].should.match(/NOW/);
530+
526531
const res = await dbRunner.testQueries(minMaxQueries);
527532

528533
res.should.be.deepEqual(
@@ -1127,6 +1132,7 @@ describe('PreAggregations in time hierarchy', function test() {
11271132
});
11281133
});
11291134
});
1135+
11301136
it('query on week match to pre-agg on day', () => {
11311137
return compiler.compile().then(() => {
11321138
const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, {

0 commit comments

Comments
 (0)