Skip to content

Commit

Permalink
fix(api-gateway): Allow querying time dimensions with custom granular…
Browse files Browse the repository at this point in the history
…ity (#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]>
  • Loading branch information
LFischerstrom and KSDaemon authored Jan 15, 2025
1 parent c8f24f7 commit 80f10ce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/cubejs-api-gateway/src/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
24 changes: 23 additions & 1 deletion packages/cubejs-api-gateway/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();

Expand Down

0 comments on commit 80f10ce

Please sign in to comment.