Skip to content

feat(tesseract): Support calendar cubes and custom sql granularities #9698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/cubejs-schema-compiler/src/compiler/CubeSymbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface CubeDefinition {
excludes?: any;
cubes?: any;
isView?: boolean;
calendar?: boolean;
isSplitView?: boolean;
includedMembers?: any[];
}
Expand Down Expand Up @@ -979,8 +980,17 @@ export class CubeSymbols {
const [cubeName, dimName, gr, granName] = Array.isArray(path) ? path : path.split('.');
const cube = refCube || this.symbols[cubeName];

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

return { interval: `1 ${granName}` };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ const BaseDimensionWithoutSubQuery = {
return isValid ? value : helper.message(msg);
}),
offset: GranularityOffset.optional(),
}),
Joi.object().keys({
title: Joi.string(),
sql: Joi.func().required()
})
])).optional(),
otherwise: Joi.forbidden()
Expand Down Expand Up @@ -786,6 +790,7 @@ const baseSchema = {
const cubeSchema = inherit(baseSchema, {
sql: Joi.func(),
sqlTable: Joi.func(),
calendar: Joi.boolean().strict(),
}).xor('sql', 'sqlTable').messages({
'object.xor': 'You must use either sql or sqlTable within a model, but not both'
});
Expand Down
Loading
Loading