Skip to content

Commit 22f6102

Browse files
authored
feat(schema-compiler): quarter granularity (#6285)
1 parent 711701b commit 22f6102

File tree

4 files changed

+50
-6
lines changed

4 files changed

+50
-6
lines changed

docs/content/API-Reference/Query-Format.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,9 @@ provides a convenient shortcut to pass a dimension and a filter as a
526526
- `compareDateRange`: An array of date ranges to compare a measure change over
527527
previous period
528528
- `granularity`: A granularity for a time dimension. It supports the following
529-
values `second`, `minute`, `hour`, `day`, `week`, `month`, `year`. If you pass
530-
`null` to the granularity, Cube will only perform filtering by a specified
531-
time dimension, without grouping.
529+
values `second`, `minute`, `hour`, `day`, `week`, `month`, `quarter`, `year`.
530+
If you pass `null` to the granularity, Cube will only perform filtering by
531+
a specified time dimension, without grouping.
532532

533533
```javascript
534534
{

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ const identifierRegex = /^[_a-zA-Z][_a-zA-Z0-9]*$/;
2828
const identifier = Joi.string().regex(identifierRegex, 'identifier');
2929

3030
const regexTimeInterval = Joi.string().custom((value, helper) => {
31-
if (value.match(/^(-?\d+) (minute|hour|day|week|month|year)$/)) {
31+
if (value.match(/^(-?\d+) (minute|hour|day|week|month|quarter|year)$/)) {
3232
return value;
3333
} else {
34-
return helper.message({ custom: `(${helper.state.path.join('.')} = ${value}) does not match regexp: /^(-?\\d+) (minute|hour|day|week|month|year)$/` });
34+
return helper.message({ custom: `(${helper.state.path.join('.')} = ${value}) does not match regexp: /^(-?\\d+) (minute|hour|day|week|month|quarter|year)$/` });
3535
}
3636
});
3737

@@ -233,7 +233,7 @@ const OriginalSqlSchema = condition(
233233
}),
234234
);
235235

236-
const GranularitySchema = Joi.string().valid('second', 'minute', 'hour', 'day', 'week', 'month', 'year').required();
236+
const GranularitySchema = Joi.string().valid('second', 'minute', 'hour', 'day', 'week', 'month', 'quarter', 'year').required();
237237

238238
const ReferencesFields = ['timeDimensionReference', 'rollupReferences', 'measureReferences', 'dimensionReferences', 'segmentReferences'];
239239
const NonReferencesFields = ['timeDimension', 'rollups', 'measures', 'dimensions', 'segments'];

packages/cubejs-testing/test/__snapshots__/birdbox-postgresql-pre-aggregations.test.ts.snap

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,29 @@ Array [
9696
]
9797
`;
9898

99+
exports[`postgresql-cubestore HTTP Transport Rolling with Quarter granularity: Rolling with Quarter granularity 1`] = `
100+
Array [
101+
Object {
102+
"visitors.checkinsRollingTotal": "0",
103+
"visitors.createdAt": "2017-01-01T00:00:00.000",
104+
"visitors.createdAt.quarter": "2017-01-01T00:00:00.000",
105+
"visitors.source": null,
106+
},
107+
Object {
108+
"visitors.checkinsRollingTotal": "1",
109+
"visitors.createdAt": "2017-01-01T00:00:00.000",
110+
"visitors.createdAt.quarter": "2017-01-01T00:00:00.000",
111+
"visitors.source": "google",
112+
},
113+
Object {
114+
"visitors.checkinsRollingTotal": "5",
115+
"visitors.createdAt": "2017-01-01T00:00:00.000",
116+
"visitors.createdAt.quarter": "2017-01-01T00:00:00.000",
117+
"visitors.source": "some",
118+
},
119+
]
120+
`;
121+
99122
exports[`postgresql-cubestore HTTP Transport Rolling: Rolling 1`] = `
100123
Array [
101124
Object {

packages/cubejs-testing/test/pre-aggregations-test-case.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,27 @@ const asserts: [options: QueryTestOptions, query: Query][] = [
3232
}
3333
}
3434
],
35+
[
36+
{ name: 'Rolling with Quarter granularity' },
37+
{
38+
measures: [
39+
'visitors.checkinsRollingTotal',
40+
],
41+
dimensions: [
42+
'visitors.source'
43+
],
44+
timezone: 'UTC',
45+
timeDimensions: [{
46+
dimension: 'visitors.createdAt',
47+
granularity: 'quarter',
48+
dateRange: ['2017-01-01', '2017-01-05']
49+
}],
50+
order: {
51+
'visitors.createdAt': 'asc',
52+
'visitors.source': 'asc'
53+
}
54+
}
55+
],
3556
[
3657
{ name: 'Rolling Mixed' },
3758
{

0 commit comments

Comments
 (0)