diff --git a/packages/cubejs-api-gateway/src/query.js b/packages/cubejs-api-gateway/src/query.js index 18735bbcc7d93..a3d323d5ca758 100644 --- a/packages/cubejs-api-gateway/src/query.js +++ b/packages/cubejs-api-gateway/src/query.js @@ -40,7 +40,7 @@ const getPivotQuery = (queryType, queries) => { const id = Joi.string().regex(/^[a-zA-Z0-9_]+\.[a-zA-Z0-9_]+$/); const idOrMemberExpressionName = Joi.string().regex(/^[a-zA-Z0-9_]+\.[a-zA-Z0-9_]+$|^[a-zA-Z0-9_]+$/); -const dimensionWithTime = Joi.string().regex(/^[a-zA-Z0-9_]+\.[a-zA-Z0-9_]+(\.(second|minute|hour|day|week|month|year))?$/); +const dimensionWithTime = Joi.string().regex(/^[a-zA-Z0-9_]+\.[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)?$/); const parsedMemberExpression = Joi.object().keys({ expression: Joi.array().items(Joi.string()).min(1).required(), cubeName: Joi.string().required(), diff --git a/packages/cubejs-api-gateway/test/index.test.ts b/packages/cubejs-api-gateway/test/index.test.ts index bdff7907ee703..b7436e3093cae 100644 --- a/packages/cubejs-api-gateway/test/index.test.ts +++ b/packages/cubejs-api-gateway/test/index.test.ts @@ -316,7 +316,7 @@ describe('API Gateway', () => { expect(res.body && res.body.data).toStrictEqual([{ 'Foo.bar': 42 }]); }); - test('custom granularities in annotation', async () => { + test('custom granularities in annotation from timeDimensions', async () => { const { app } = await createApiGateway(); const res = await request(app) @@ -338,6 +338,28 @@ describe('API Gateway', () => { }); }); + test('custom granularities in annotation from dimensions', async () => { + const { app } = await createApiGateway(); + + const res = await request(app) + .get( + '/cubejs-api/v1/load?query={"measures":["Foo.bar"],"dimensions":["Foo.timeGranularities.half_year_by_1st_april"]}' + ) + .set('Authorization', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M') + .expect(200); + console.log(res.body); + expect(res.body && res.body.data).toStrictEqual([{ 'Foo.bar': 42 }]); + expect(res.body.annotation.timeDimensions['Foo.timeGranularities.half_year_by_1st_april']) + .toStrictEqual({ + granularity: { + name: 'half_year_by_1st_april', + title: 'Half Year By1 St April', + interval: '6 months', + offset: '3 months', + } + }); + }); + test('dry-run', async () => { const { app } = await createApiGateway();