Skip to content

Commit 8b67801

Browse files
KSDaemonFrank-TXS
authored andcommitted
feat(tesseract): Support calendar cubes and custom sql granularities (cube-js#9698)
* add support for calendar prop and sql in granularities in schema validator * fix resolveGranularity() for calendar td granularities * support granularities sql() in tesseract * fix td symbol deps * cargo fmt * add tests for calendar cubes in schema compiler * add calendar tests
1 parent 4eecf01 commit 8b67801

File tree

19 files changed

+1282
-38
lines changed

19 files changed

+1282
-38
lines changed

packages/cubejs-schema-compiler/src/compiler/CubeSymbols.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ interface CubeDefinition {
3131
excludes?: any;
3232
cubes?: any;
3333
isView?: boolean;
34+
calendar?: boolean;
3435
isSplitView?: boolean;
3536
includedMembers?: any[];
3637
}
@@ -982,8 +983,17 @@ export class CubeSymbols {
982983
const [cubeName, dimName, gr, granName] = Array.isArray(path) ? path : path.split('.');
983984
const cube = refCube || this.symbols[cubeName];
984985

985-
// Predefined granularity
986+
// Calendar cubes time dimensions may define custom sql for predefined granularities,
987+
// so we need to check if such granularity exists in cube definition.
986988
if (typeof granName === 'string' && /^(second|minute|hour|day|week|month|quarter|year)$/i.test(granName)) {
989+
const customGranularity = cube?.[dimName]?.[gr]?.[granName];
990+
if (customGranularity) {
991+
return {
992+
...customGranularity,
993+
interval: `1 ${granName}`, // It's still important to have interval for granularity math
994+
};
995+
}
996+
987997
return { interval: `1 ${granName}` };
988998
}
989999

packages/cubejs-schema-compiler/src/compiler/CubeValidator.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ const BaseDimensionWithoutSubQuery = {
185185
return isValid ? value : helper.message(msg);
186186
}),
187187
offset: GranularityOffset.optional(),
188+
}),
189+
Joi.object().keys({
190+
title: Joi.string(),
191+
sql: Joi.func().required()
188192
})
189193
])).optional(),
190194
otherwise: Joi.forbidden()
@@ -786,6 +790,7 @@ const baseSchema = {
786790
const cubeSchema = inherit(baseSchema, {
787791
sql: Joi.func(),
788792
sqlTable: Joi.func(),
793+
calendar: Joi.boolean().strict(),
789794
}).xor('sql', 'sqlTable').messages({
790795
'object.xor': 'You must use either sql or sqlTable within a model, but not both'
791796
});

0 commit comments

Comments
 (0)