Skip to content

Commit 80f10ce

Browse files
fix(api-gateway): Allow querying time dimensions with custom granularity (#9068)
* fix: allow dimensions with quarter granularity * Update packages/cubejs-api-gateway/src/query.js Co-authored-by: Konstantin Burkalev <[email protected]> * Add test for custom granularities from dimensions * fix --------- Co-authored-by: Konstantin Burkalev <[email protected]>
1 parent c8f24f7 commit 80f10ce

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

packages/cubejs-api-gateway/src/query.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const getPivotQuery = (queryType, queries) => {
4040

4141
const id = Joi.string().regex(/^[a-zA-Z0-9_]+\.[a-zA-Z0-9_]+$/);
4242
const idOrMemberExpressionName = Joi.string().regex(/^[a-zA-Z0-9_]+\.[a-zA-Z0-9_]+$|^[a-zA-Z0-9_]+$/);
43-
const dimensionWithTime = Joi.string().regex(/^[a-zA-Z0-9_]+\.[a-zA-Z0-9_]+(\.(second|minute|hour|day|week|month|year))?$/);
43+
const dimensionWithTime = Joi.string().regex(/^[a-zA-Z0-9_]+\.[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)?$/);
4444
const parsedMemberExpression = Joi.object().keys({
4545
expression: Joi.array().items(Joi.string()).min(1).required(),
4646
cubeName: Joi.string().required(),

packages/cubejs-api-gateway/test/index.test.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ describe('API Gateway', () => {
316316
expect(res.body && res.body.data).toStrictEqual([{ 'Foo.bar': 42 }]);
317317
});
318318

319-
test('custom granularities in annotation', async () => {
319+
test('custom granularities in annotation from timeDimensions', async () => {
320320
const { app } = await createApiGateway();
321321

322322
const res = await request(app)
@@ -338,6 +338,28 @@ describe('API Gateway', () => {
338338
});
339339
});
340340

341+
test('custom granularities in annotation from dimensions', async () => {
342+
const { app } = await createApiGateway();
343+
344+
const res = await request(app)
345+
.get(
346+
'/cubejs-api/v1/load?query={"measures":["Foo.bar"],"dimensions":["Foo.timeGranularities.half_year_by_1st_april"]}'
347+
)
348+
.set('Authorization', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M')
349+
.expect(200);
350+
console.log(res.body);
351+
expect(res.body && res.body.data).toStrictEqual([{ 'Foo.bar': 42 }]);
352+
expect(res.body.annotation.timeDimensions['Foo.timeGranularities.half_year_by_1st_april'])
353+
.toStrictEqual({
354+
granularity: {
355+
name: 'half_year_by_1st_april',
356+
title: 'Half Year By1 St April',
357+
interval: '6 months',
358+
offset: '3 months',
359+
}
360+
});
361+
});
362+
341363
test('dry-run', async () => {
342364
const { app } = await createApiGateway();
343365

0 commit comments

Comments
 (0)