Skip to content

Commit 995889f

Browse files
authored
feat(cubesql): Compiler cache for rewrite rules (#7604)
* feat(cubesql): Compiler cache for rewrite rules * Fix chrono dependency version mismatch * Fix tests
1 parent e39c202 commit 995889f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+783
-419
lines changed

packages/cubejs-api-gateway/src/gateway.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {
4040
PreAggJobStatusItem,
4141
PreAggJobStatusObject,
4242
PreAggJobStatusResponse,
43-
SqlApiRequest,
43+
SqlApiRequest, MetaResponseResultFn,
4444
} from './types/request';
4545
import {
4646
CheckAuthInternalOptions,
@@ -481,12 +481,12 @@ class ApiGateway {
481481
}
482482
}
483483

484-
private filterVisibleItemsInMeta(context: RequestContext, metaConfig: any) {
484+
private filterVisibleItemsInMeta(context: RequestContext, cubes: any[]) {
485485
function visibilityFilter(item) {
486486
return getEnv('devMode') || context.signedWithPlaygroundAuthSecret || item.isVisible;
487487
}
488488

489-
return metaConfig
489+
return cubes
490490
.map((cube) => ({
491491
config: {
492492
...cube.config,
@@ -497,17 +497,27 @@ class ApiGateway {
497497
})).filter(cube => cube.config.measures?.length || cube.config.dimensions?.length || cube.config.segments?.length);
498498
}
499499

500-
public async meta({ context, res }: { context: RequestContext, res: ResponseResultFn }) {
500+
public async meta({ context, res, includeCompilerId }: {
501+
context: RequestContext,
502+
res: MetaResponseResultFn,
503+
includeCompilerId?: boolean
504+
}) {
501505
const requestStarted = new Date();
502506

503507
try {
504508
await this.assertApiScope('meta', context.securityContext);
505509
const compilerApi = await this.getCompilerApi(context);
506510
const metaConfig = await compilerApi.metaConfig({
507511
requestId: context.requestId,
512+
includeCompilerId
508513
});
509-
const cubes = this.filterVisibleItemsInMeta(context, metaConfig).map(cube => cube.config);
510-
res({ cubes });
514+
const cubesConfig = includeCompilerId ? metaConfig.cubes : metaConfig;
515+
const cubes = this.filterVisibleItemsInMeta(context, cubesConfig).map(cube => cube.config);
516+
const response: { cubes: any[], compilerId?: string } = { cubes };
517+
if (includeCompilerId) {
518+
response.compilerId = metaConfig.compilerId;
519+
}
520+
res(response);
511521
} catch (e) {
512522
this.handleError({
513523
e,

packages/cubejs-api-gateway/src/sql-server.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class SQLServer {
8181
skipPasswordCheck,
8282
};
8383
},
84-
meta: async ({ request, session }) => {
84+
meta: async ({ request, session, onlyCompilerId }) => {
8585
const context = await this.apiGateway.contextByReq(<any> request, session.securityContext, request.id);
8686

8787
// eslint-disable-next-line no-async-promise-executor
@@ -90,8 +90,13 @@ export class SQLServer {
9090
await this.apiGateway.meta({
9191
context,
9292
res: (message) => {
93-
resolve(message);
93+
if (onlyCompilerId) {
94+
resolve({ compilerId: message.compilerId });
95+
} else {
96+
resolve(message);
97+
}
9498
},
99+
includeCompilerId: true
95100
});
96101
} catch (e) {
97102
reject(e);

packages/cubejs-api-gateway/src/types/request.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ type ResponseResultFn =
100100
extra?: { status: number }
101101
) => void;
102102

103+
type MetaResponseResultFn =
104+
(
105+
message: { cubes: any[], compilerId?: string }
106+
) => void;
107+
103108
/**
104109
* Base HTTP request parameters map data type.
105110
* @todo map it to Request.
@@ -199,6 +204,7 @@ export {
199204
SecurityContextExtractorFn,
200205
ExtendContextFn,
201206
ResponseResultFn,
207+
MetaResponseResultFn,
202208
BaseRequest,
203209
QueryRequest,
204210
PreAggsJobsRequest,

packages/cubejs-backend-native/Cargo.lock

Lines changed: 56 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)