Skip to content

Commit f2000c0

Browse files
committed
feat: RefreshKeys helper extension of popular implementations
1 parent c873a83 commit f2000c0

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const ContextEvaluator = require('./ContextEvaluator');
99
const DashboardTemplateEvaluator = require('./DashboardTemplateEvaluator');
1010
const JoinGraph = require('./JoinGraph');
1111
const Funnels = require('../extensions/Funnels');
12+
const RefreshKeys = require('../extensions/RefreshKeys');
1213
const CubeToMetaTransformer = require('./CubeToMetaTransformer');
1314

1415
exports.compile = (repo, options) => {
@@ -36,7 +37,8 @@ exports.prepareCompiler = (repo, options) => {
3637
dashboardTemplateCompilers: [dashboardTemplateEvaluator],
3738
cubeFactory: cubeSymbols.createCube.bind(cubeSymbols),
3839
extensions: {
39-
Funnels
40+
Funnels,
41+
RefreshKeys
4042
}
4143
}, options));
4244
return {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class RefreshKeys {
2+
constructor(cubeFactory, compiler) {
3+
this.cubeFactory = cubeFactory;
4+
this.compiler = compiler;
5+
this.immutablePartitionedRollupKey = this.immutablePartitionedRollupKey.bind(this);
6+
}
7+
8+
immutablePartitionedRollupKey(scalarValue) {
9+
return {
10+
sql: (FILTER_PARAMS) => `SELECT ${this.compiler.contextQuery().caseWhenStatement([{
11+
sql: FILTER_PARAMS[
12+
this.compiler.contextQuery().timeDimensions[0].path()[0]
13+
][
14+
this.compiler.contextQuery().timeDimensions[0].path()[1]
15+
].filter(
16+
(from, to) => `${this.compiler.contextQuery().nowTimestampSql()} < ${this.compiler.contextQuery().timeStampCast(to)}`
17+
),
18+
label: scalarValue
19+
}])}`
20+
};
21+
}
22+
}
23+
24+
module.exports = RefreshKeys;

0 commit comments

Comments
 (0)