Skip to content
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

fix(api-gateway): Allow querying time dimensions with custom granularity #9068

Merged
Merged
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
Loading