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

chore(schema-compiler): Collect sqlTable in CubeToMetaTransformer #8333

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/cubejs-api-gateway/src/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@

protected readonly playgroundAuthSecret?: string;

protected readonly event: (name: string, props?: object) => void;

Check warning on line 156 in packages/cubejs-api-gateway/src/gateway.ts

View workflow job for this annotation

GitHub Actions / lint

'name' is defined but never used. Allowed unused args must match /^_.*/u

Check warning on line 156 in packages/cubejs-api-gateway/src/gateway.ts

View workflow job for this annotation

GitHub Actions / lint

'props' is defined but never used. Allowed unused args must match /^_.*/u

public constructor(
protected readonly apiSecret: string,
Expand Down Expand Up @@ -186,7 +186,7 @@
this.contextRejectionMiddleware = options.contextRejectionMiddleware || (async (req, res, next) => next());
this.wsContextAcceptor = options.wsContextAcceptor || (() => ({ accepted: true }));
// eslint-disable-next-line @typescript-eslint/no-empty-function
this.event = options.event || function () {};

Check warning on line 189 in packages/cubejs-api-gateway/src/gateway.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected unnamed function
}

public initApp(app: ExpressApplication) {
Expand Down Expand Up @@ -579,7 +579,11 @@
return;
}
const cubesConfig = includeCompilerId ? metaConfig.cubes : metaConfig;
const cubes = this.filterVisibleItemsInMeta(context, cubesConfig).map(cube => cube.config);
const cubes = this.filterVisibleItemsInMeta(context, cubesConfig).map(cube => ({
...cube.config,
// we dont want to expose sqlTable
sqlTable: undefined,
}));
const response: { cubes: any[], compilerId?: string } = { cubes };
if (includeCompilerId) {
response.compilerId = metaConfig.compilerId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
};
}

function transformCube(cube: any, cubeDefinitions: any) {
function transformCube(cube: any, cubeDefinitions: any, extended: boolean = true) {

Check warning on line 37 in packages/cubejs-api-gateway/src/helpers/transformMetaExtended.ts

View workflow job for this annotation

GitHub Actions / lint

'extended' is assigned a value but never used. Allowed unused vars must match /^_.*/u
return {
...cube,
// we dont want to expose sqlTable
sqlTable: undefined,
extends: stringifyMemberSql(cubeDefinitions[cube?.name]?.extends),
sql: stringifyMemberSql(cubeDefinitions[cube?.name]?.sql),
fileName: cubeDefinitions[cube?.name]?.fileName,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`API Gateway meta endpoint extended to get schema information with additional data 1`] = `
Array [
Object {
"dimensions": Array [
Object {
"isVisible": true,
"name": "Foo.id",
},
Object {
"isVisible": true,
"name": "Foo.time",
},
],
"measures": Array [
Object {
"isVisible": true,
"name": "Foo.bar",
},
],
"name": "Foo",
"sql": "'SELECT * FROM Foo'",
},
]
`;

exports[`API Gateway meta endpoint to get schema information 1`] = `
Array [
Object {
"dimensions": Array [
Object {
"isVisible": true,
"name": "Foo.id",
},
Object {
"isVisible": true,
"name": "Foo.time",
},
],
"measures": Array [
Object {
"isVisible": true,
"name": "Foo.bar",
},
],
"name": "Foo",
"title": "My Cube called Foo",
"type": "cube",
},
Object {
"dimensions": Array [
Object {
"isVisible": true,
"name": "Bar.id",
},
Object {
"isVisible": true,
"name": "Bar.time",
},
],
"measures": Array [
Object {
"isVisible": true,
"name": "Bar.bar",
},
],
"name": "Bar",
"title": "My Cube called Bar",
"type": "cube",
},
]
`;
4 changes: 4 additions & 0 deletions packages/cubejs-api-gateway/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@
req.authInfo = authorization;
}
},
queryRewrite: async (query, context) => {

Check warning on line 403 in packages/cubejs-api-gateway/test/index.test.ts

View workflow job for this annotation

GitHub Actions / lint

'context' is defined but never used. Allowed unused args must match /^_.*/u
query.limit = 2;
return query;
}
Expand Down Expand Up @@ -583,6 +583,8 @@
expect(res.body).toHaveProperty('cubes');
expect(res.body.cubes[0]?.name).toBe('Foo');
expect(res.body.cubes[0]?.hasOwnProperty('sql')).toBe(false);

expect(res.body.cubes).toMatchSnapshot();
});

test('meta endpoint extended to get schema information with additional data', async () => {
Expand All @@ -596,6 +598,8 @@
expect(res.body).toHaveProperty('cubes');
expect(res.body.cubes[0]?.name).toBe('Foo');
expect(res.body.cubes[0]?.hasOwnProperty('sql')).toBe(true);

expect(res.body.cubes).toMatchSnapshot();
});

describe('multi query support', () => {
Expand Down Expand Up @@ -737,7 +741,7 @@
expect(res.body).toMatchObject(successResult);
};

const wrongPayloadsTestFactory = ({ route, wrongPayloads, scope }: {

Check warning on line 744 in packages/cubejs-api-gateway/test/index.test.ts

View workflow job for this annotation

GitHub Actions / lint

'wrongPayloadsTestFactory' is assigned a value but never used. Allowed unused vars must match /^_.*/u
route: string,
method: string,
scope?: string[],
Expand Down
26 changes: 26 additions & 0 deletions packages/cubejs-api-gateway/test/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export const compilerApi = jest.fn().mockImplementation(async () => ({
{
config: {
name: 'Foo',
type: 'cube',
title: 'My Cube called Foo',
measures: [
{
name: 'Foo.bar',
Expand All @@ -98,6 +100,30 @@ export const compilerApi = jest.fn().mockImplementation(async () => ({
],
},
},
{
config: {
name: 'Bar',
type: 'cube',
title: 'My Cube called Bar',
sqlTable: 'my_sql_table',
measures: [
{
name: 'Bar.bar',
isVisible: true,
},
],
dimensions: [
{
name: 'Bar.id',
isVisible: true,
},
{
name: 'Bar.time',
isVisible: true,
},
],
},
}
];
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export class CubeToMetaTransformer {
description: cube.description,
connectedComponent: this.joinGraph.connectedComponents()[cube.name],
meta: cube.meta,
sqlTable: cube.sqlTable && this.cubeEvaluator.evaluateReferences(
cube.name, cube.sqlTable, {}
),
measures: R.compose(
R.map((nameToMetric) => ({
...this.measureConfig(cube.name, cubeTitle, nameToMetric),
Expand Down
2 changes: 2 additions & 0 deletions packages/cubejs-server-core/src/core/CompilerApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,13 @@ export class CompilerApi {
compilerId: compilers.compilerId,
};
}

return compilers.metaTransformer.cubes;
}

async metaConfigExtended(options) {
const { metaTransformer } = await this.getCompilers(options);

return {
metaConfig: metaTransformer?.cubes,
cubeDefinitions: metaTransformer?.cubeEvaluator?.cubeDefinitions,
Expand Down
5 changes: 5 additions & 0 deletions packages/cubejs-testing-drivers/src/tests/testQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ export function testQueries(type: string, { includeIncrementalSchemaSuite, exten
}
});

execute('meta snapshot', async () => {
const meta = await client.meta();
expect(meta.cubes).toMatchSnapshot();
});

execute('must not fetch a hidden cube', async () => {
const meta = await client.meta();
expect(meta.cubes.find(cube => cube.name === 'HiddenECommerce')).toBe(undefined);
Expand Down
Loading
Loading