@cubejs-backend/server-core 1.8.6 → 1.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/core/CompilerApi.d.ts +27 -0
- package/dist/src/core/CompilerApi.d.ts.map +1 -1
- package/dist/src/core/CompilerApi.js +199 -19
- package/dist/src/core/CompilerApi.js.map +1 -1
- package/dist/src/core/OptsHandler.d.ts.map +1 -1
- package/dist/src/core/OptsHandler.js +1 -0
- package/dist/src/core/OptsHandler.js.map +1 -1
- package/dist/src/core/RefreshScheduler.d.ts.map +1 -1
- package/dist/src/core/RefreshScheduler.js +6 -8
- package/dist/src/core/RefreshScheduler.js.map +1 -1
- package/dist/src/core/optionsValidate.d.ts.map +1 -1
- package/dist/src/core/optionsValidate.js +1 -0
- package/dist/src/core/optionsValidate.js.map +1 -1
- package/dist/src/core/server.d.ts +5 -0
- package/dist/src/core/server.d.ts.map +1 -1
- package/dist/src/core/server.js +54 -0
- package/dist/src/core/server.js.map +1 -1
- package/dist/src/core/types.d.ts +2 -1
- package/dist/src/core/types.d.ts.map +1 -1
- package/package.json +13 -13
- package/playground/vizard/download/react-typescript-antd-table.zip +0 -0
- package/playground/vizard/download/react-typescript-chartjs-area+bar+doughnut+line+pie.zip +0 -0
|
@@ -22,6 +22,8 @@ export interface CompilerApiOptions {
|
|
|
22
22
|
sqlCache?: boolean;
|
|
23
23
|
standalone?: boolean;
|
|
24
24
|
compilerCacheSize?: number;
|
|
25
|
+
/** Called once a compile succeeds, so the owner can re-check its member budget. */
|
|
26
|
+
onCompiled?: () => void;
|
|
25
27
|
maxCompilerCacheKeepAlive?: number;
|
|
26
28
|
updateCompilerCacheKeepAlive?: boolean;
|
|
27
29
|
/**
|
|
@@ -89,11 +91,23 @@ export declare class CompilerApi {
|
|
|
89
91
|
protected compilers?: Promise<Compiler>;
|
|
90
92
|
protected compilerVersion?: string;
|
|
91
93
|
protected queryFactory?: QueryFactory;
|
|
94
|
+
/**
|
|
95
|
+
* Each compile's own factory. A request holds `compilers` across awaits, and
|
|
96
|
+
* reading `this.queryFactory` then could pair them with a newer model's
|
|
97
|
+
* factory or, after eviction, with the disposed proxy.
|
|
98
|
+
*/
|
|
99
|
+
private readonly queryFactories;
|
|
100
|
+
protected memberCount: number;
|
|
92
101
|
constructor(repository: SchemaFileRepository, dbType: DbTypeInternalFn, options: CompilerApiOptions);
|
|
93
102
|
dispose(): void;
|
|
94
103
|
setGraphQLSchema(schema: GraphQLSchema): void;
|
|
95
104
|
getGraphQLSchema(): GraphQLSchema;
|
|
96
105
|
createNativeInstance(): NativeInstance;
|
|
106
|
+
/**
|
|
107
|
+
* Members (measures, dimensions, segments) of the model this entry holds, across
|
|
108
|
+
* every cube and view. Zero while a compile is in flight or after one failed.
|
|
109
|
+
*/
|
|
110
|
+
get compiledMemberCount(): number;
|
|
97
111
|
getCompilers(options?: {
|
|
98
112
|
requestId?: string;
|
|
99
113
|
}): Promise<Compiler>;
|
|
@@ -102,6 +116,8 @@ export declare class CompilerApi {
|
|
|
102
116
|
* because it could fail and no compilers will be returned.
|
|
103
117
|
*/
|
|
104
118
|
createCompilerInstances(): Compiler;
|
|
119
|
+
/** Members across every cube and view, views included: that is where a wide model's usually are. */
|
|
120
|
+
private static countMembers;
|
|
105
121
|
compileSchema(compilerVersion: string, requestId?: string): Promise<Compiler>;
|
|
106
122
|
createQueryFactory(compilers: Compiler): Promise<QueryFactory>;
|
|
107
123
|
getDbType(dataSource?: string): Promise<string>;
|
|
@@ -132,6 +148,11 @@ export declare class CompilerApi {
|
|
|
132
148
|
query: NormalizedQuery;
|
|
133
149
|
denied: boolean;
|
|
134
150
|
}>;
|
|
151
|
+
/**
|
|
152
|
+
* Moves a filter on members of `cubeName` onto the cube instance at
|
|
153
|
+
* `instancePath`. Policy filters only name members of their own cube.
|
|
154
|
+
*/
|
|
155
|
+
protected rebaseFilterMembers(filter: any, cubeName: string, instancePath: string): any;
|
|
135
156
|
protected filterMemberName(filter: any): string | undefined;
|
|
136
157
|
/**
|
|
137
158
|
* Collects the leaf conditions that are guaranteed to hold for every row a
|
|
@@ -157,6 +178,12 @@ export declare class CompilerApi {
|
|
|
157
178
|
protected removeEmptyFilters(filter: any): any;
|
|
158
179
|
compilerCacheFn(requestId: string, key: any, path: string[]): Promise<(subKey: string[], cacheFn: () => any) => any>;
|
|
159
180
|
preAggregations(filter?: PreAggregationFilters): Promise<PreAggregationInfo[]>;
|
|
181
|
+
/**
|
|
182
|
+
* The members each external rollup may serve, one array per rollup (views in their own
|
|
183
|
+
* names): cubesql plans a scan over a pre-aggregation only when its members fit one.
|
|
184
|
+
*/
|
|
185
|
+
externalPreAggregationMembers(): Promise<string[][]>;
|
|
186
|
+
protected collectExternalPreAggregationMembers(cubeEvaluator: any, query: any): string[][];
|
|
160
187
|
scheduledPreAggregations(): Promise<PreAggregationInfo[]>;
|
|
161
188
|
createQueryByDataSource(compilers: Compiler, query: NormalizedQuery | {}, dataSource?: string, dbType?: string): Promise<BaseQuery>;
|
|
162
189
|
createQuery(compilers: Compiler, dbType: string, dialectClass: BaseQuery, query: NormalizedQuery | {}): BaseQuery;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CompilerApi.d.ts","sourceRoot":"","sources":["../../../src/core/CompilerApi.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAEL,SAAS,EACT,sBAAsB,EAEtB,QAAQ,EAER,cAAc,EACd,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,wBAAwB,EAIxB,YAAY,EACZ,gBAAgB,EAEjB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;A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 +38,13 @@ class CompilerApi {
|
|
|
38
38
|
compilers;
|
|
39
39
|
compilerVersion;
|
|
40
40
|
queryFactory;
|
|
41
|
+
/**
|
|
42
|
+
* Each compile's own factory. A request holds `compilers` across awaits, and
|
|
43
|
+
* reading `this.queryFactory` then could pair them with a newer model's
|
|
44
|
+
* factory or, after eviction, with the disposed proxy.
|
|
45
|
+
*/
|
|
46
|
+
queryFactories = new WeakMap();
|
|
47
|
+
memberCount = 0;
|
|
41
48
|
constructor(repository, dbType, options) {
|
|
42
49
|
this.repository = repository;
|
|
43
50
|
this.dbType = dbType;
|
|
@@ -99,6 +106,10 @@ class CompilerApi {
|
|
|
99
106
|
this.compilers = (0, shared_1.disposedProxy)('compilers', 'disposed CompilerApi instance');
|
|
100
107
|
this.queryFactory = (0, shared_1.disposedProxy)('queryFactory', 'disposed CompilerApi instance');
|
|
101
108
|
this.graphqlSchema = undefined;
|
|
109
|
+
// A request can still hold this instance -- the gateway keeps one across
|
|
110
|
+
// several awaits. Clearing the version makes its next getCompilers()
|
|
111
|
+
// recompile rather than hand back the proxy, which throws on `.then`.
|
|
112
|
+
this.compilerVersion = undefined;
|
|
102
113
|
}
|
|
103
114
|
setGraphQLSchema(schema) {
|
|
104
115
|
this.graphqlSchema = schema;
|
|
@@ -109,6 +120,13 @@ class CompilerApi {
|
|
|
109
120
|
createNativeInstance() {
|
|
110
121
|
return new native_1.NativeInstance();
|
|
111
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Members (measures, dimensions, segments) of the model this entry holds, across
|
|
125
|
+
* every cube and view. Zero while a compile is in flight or after one failed.
|
|
126
|
+
*/
|
|
127
|
+
get compiledMemberCount() {
|
|
128
|
+
return this.memberCount;
|
|
129
|
+
}
|
|
112
130
|
async getCompilers(options = {}) {
|
|
113
131
|
let compilerVersion = (this.schemaVersion && await this.schemaVersion() ||
|
|
114
132
|
'default_schema_version');
|
|
@@ -143,8 +161,19 @@ class CompilerApi {
|
|
|
143
161
|
multiTenantSharing: this.multiTenantSharing,
|
|
144
162
|
});
|
|
145
163
|
}
|
|
164
|
+
/** Members across every cube and view, views included: that is where a wide model's usually are. */
|
|
165
|
+
static countMembers(compilers) {
|
|
166
|
+
return compilers.cubeEvaluator.cubeList.reduce((total, cube) => total
|
|
167
|
+
+ Object.keys(cube.measures || {}).length
|
|
168
|
+
+ Object.keys(cube.dimensions || {}).length
|
|
169
|
+
+ Object.keys(cube.segments || {}).length, 0);
|
|
170
|
+
}
|
|
146
171
|
async compileSchema(compilerVersion, requestId) {
|
|
147
172
|
const startCompilingTime = new Date().getTime();
|
|
173
|
+
// A recompile replaces `compilers` with the new promise, so the previous
|
|
174
|
+
// model is no longer held here -- and counting it would let the budget walk
|
|
175
|
+
// evict this entry while the compile it would throw away is still running.
|
|
176
|
+
this.memberCount = 0;
|
|
148
177
|
try {
|
|
149
178
|
this.logger(this.compilers ? 'Recompiling schema' : 'Compiling schema', {
|
|
150
179
|
version: compilerVersion,
|
|
@@ -162,6 +191,22 @@ class CompilerApi {
|
|
|
162
191
|
compiledYamlCache: this.compiledYamlCache,
|
|
163
192
|
});
|
|
164
193
|
this.queryFactory = await this.createQueryFactory(compilers);
|
|
194
|
+
this.queryFactories.set(compilers, this.queryFactory);
|
|
195
|
+
// A compile that a newer version superseded, or that finished on an
|
|
196
|
+
// evicted instance, no longer describes what this entry holds.
|
|
197
|
+
if (this.compilerVersion === compilerVersion) {
|
|
198
|
+
this.memberCount = CompilerApi.countMembers(compilers);
|
|
199
|
+
// Housekeeping for other entries: if it fails, this compile still stands.
|
|
200
|
+
try {
|
|
201
|
+
this.options.onCompiled?.();
|
|
202
|
+
}
|
|
203
|
+
catch (e) {
|
|
204
|
+
this.logger('Compiler cache member budget pass failed', {
|
|
205
|
+
requestId,
|
|
206
|
+
error: (e.stack || e).toString(),
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
165
210
|
this.logger('Compiling schema completed', {
|
|
166
211
|
version: compilerVersion,
|
|
167
212
|
requestId,
|
|
@@ -181,13 +226,13 @@ class CompilerApi {
|
|
|
181
226
|
}
|
|
182
227
|
async createQueryFactory(compilers) {
|
|
183
228
|
const { cubeEvaluator } = compilers;
|
|
184
|
-
const
|
|
185
|
-
|
|
229
|
+
const dataSources = new Set(cubeEvaluator.cubeNames().map(cube => cubeEvaluator.cubeDataSource(cube)));
|
|
230
|
+
const dataSourceToQueryClass = Object.fromEntries(await Promise.all([...dataSources].map(async (dataSource) => {
|
|
186
231
|
const dbType = await this.getDbType(dataSource);
|
|
187
232
|
const dialectClass = this.getDialectClass(dataSource, dbType);
|
|
188
|
-
return [
|
|
233
|
+
return [dataSource, (0, schema_compiler_1.queryClass)(dbType, dialectClass)];
|
|
189
234
|
})));
|
|
190
|
-
return new schema_compiler_1.QueryFactory(
|
|
235
|
+
return new schema_compiler_1.QueryFactory(dataSourceToQueryClass);
|
|
191
236
|
}
|
|
192
237
|
async getDbType(dataSource = 'default') {
|
|
193
238
|
return this.dbType({ dataSource });
|
|
@@ -250,9 +295,10 @@ class CompilerApi {
|
|
|
250
295
|
const sql = await compilers.compilerCache.getQueryCache(key).cache(['sql'], getSqlFn);
|
|
251
296
|
// Relative date ranges in the data model resolve to the current time, so
|
|
252
297
|
// SQL reaching a cube with one is reused within the minute only.
|
|
253
|
-
const {
|
|
298
|
+
const { cubeEvaluator } = compilers;
|
|
299
|
+
const { relativeDateFilterCubes } = cubeEvaluator;
|
|
254
300
|
const isRelative = relativeDateFilterCubes.size > 0 &&
|
|
255
|
-
sql.memberNames?.some((member) => relativeDateFilterCubes.has(member.split('.')[0]));
|
|
301
|
+
sql.memberNames?.some((member) => relativeDateFilterCubes.has(cubeEvaluator.resolveMemberPath(member)?.targetCube ?? member.split('.')[0]));
|
|
256
302
|
if (!isRelative) {
|
|
257
303
|
return sql;
|
|
258
304
|
}
|
|
@@ -364,6 +410,31 @@ class CompilerApi {
|
|
|
364
410
|
const sql = await this.getSql(evaluatedQuery, { requestId: context?.requestId });
|
|
365
411
|
const queryMemberNames = new Set(sql.memberNames);
|
|
366
412
|
const queryCubes = new Set(sql.memberNames.map(memberName => memberName.split('.')[0]));
|
|
413
|
+
// A member reached through a join alias belongs to a cube instance: the
|
|
414
|
+
// policies of the cube it instantiates apply to it, and they constrain that
|
|
415
|
+
// instance alone. Every other member belongs to the cube it names.
|
|
416
|
+
const instances = new Map();
|
|
417
|
+
for (const memberName of queryMemberNames) {
|
|
418
|
+
const resolved = cubeEvaluator.resolveMemberPath(memberName);
|
|
419
|
+
// A path through joins that resolves to no cube instance can't be held
|
|
420
|
+
// to the policies of the cube it reads, so it is denied
|
|
421
|
+
if (!resolved?.aliased && memberName.split('.').length > 2) {
|
|
422
|
+
query.segments = query.segments || [];
|
|
423
|
+
query.segments.push({
|
|
424
|
+
expression: () => '1 = 0',
|
|
425
|
+
cubeName: memberName.split('.')[0],
|
|
426
|
+
name: 'rlsAccessDenied',
|
|
427
|
+
});
|
|
428
|
+
return { query, denied: true };
|
|
429
|
+
}
|
|
430
|
+
const [instancePath, cubeName, policyName] = resolved?.aliased ?
|
|
431
|
+
[resolved.instancePath, resolved.targetCube, resolved.targetPath] :
|
|
432
|
+
[memberName.split('.')[0], memberName.split('.')[0], memberName];
|
|
433
|
+
if (!instances.has(instancePath)) {
|
|
434
|
+
instances.set(instancePath, { cubeName, members: [] });
|
|
435
|
+
}
|
|
436
|
+
instances.get(instancePath).members.push({ name: memberName, policyName });
|
|
437
|
+
}
|
|
367
438
|
// Identify cubes that are accessed through views.
|
|
368
439
|
// Similar to PostgreSQL views: views act as a security boundary for member access.
|
|
369
440
|
// When a cube is accessed via a view, we skip the cube's member-level restrictions
|
|
@@ -382,8 +453,12 @@ class CompilerApi {
|
|
|
382
453
|
const rlsConstraints = [];
|
|
383
454
|
const maskedMembersSet = new Set();
|
|
384
455
|
const memberMaskFiltersMap = {};
|
|
385
|
-
for (const cubeName of
|
|
456
|
+
for (const [instancePath, { cubeName, members: instanceMembers }] of instances) {
|
|
386
457
|
const cube = cubeEvaluator.cubeFromPath(cubeName);
|
|
458
|
+
// The policies name the cube's own members, which the query reads
|
|
459
|
+
// through the instance
|
|
460
|
+
const onInstance = (filter) => (instancePath === cubeName ?
|
|
461
|
+
filter : this.rebaseFilterMembers(filter, cubeName, instancePath));
|
|
387
462
|
if (cubeEvaluator.isRbacEnabledForCube(cube)) {
|
|
388
463
|
const userPolicies = await this.getApplicablePolicies(cube, context, compilers);
|
|
389
464
|
// Filter out policies that don't grant member-level access to query members
|
|
@@ -480,7 +555,6 @@ class CompilerApi {
|
|
|
480
555
|
//
|
|
481
556
|
// Disjoint row ranges (R1 ∩ R2 = ∅) → empty result
|
|
482
557
|
//
|
|
483
|
-
const cubeMembersInQuery = Array.from(queryMemberNames).filter(memberName => memberName.startsWith(`${cubeName}.`));
|
|
484
558
|
// A policy "grants" a member if it exposes it through memberLevel (full
|
|
485
559
|
// access) or memberMasking (masked access). Policies without memberLevel
|
|
486
560
|
// and memberMasking expose everything, as do cubes reached through a view.
|
|
@@ -504,7 +578,7 @@ class CompilerApi {
|
|
|
504
578
|
return false;
|
|
505
579
|
};
|
|
506
580
|
const policyRowFilter = (policy) => {
|
|
507
|
-
const filters = (policy.rowLevel?.filters || []).map((filter) => this.evaluateNestedFilter(filter, cube, context, cubeEvaluator));
|
|
581
|
+
const filters = (policy.rowLevel?.filters || []).map((filter) => onInstance(this.evaluateNestedFilter(filter, cube, context, cubeEvaluator)));
|
|
508
582
|
return filters.length === 1 ? filters[0] : { and: filters };
|
|
509
583
|
};
|
|
510
584
|
const policyHasRowFilter = (policy) => !!(policy.rowLevel && !policy.rowLevel.allowAll && policy.rowLevel.filters?.length > 0);
|
|
@@ -530,7 +604,7 @@ class CompilerApi {
|
|
|
530
604
|
const memberRowConstraints = [];
|
|
531
605
|
const seenRowConstraints = new Set();
|
|
532
606
|
let cubeAccessDenied = false;
|
|
533
|
-
for (const memberName of
|
|
607
|
+
for (const { name: queryMemberName, policyName: memberName } of instanceMembers) {
|
|
534
608
|
const grantingPolicies = userPolicies.filter((policy) => policyGrantsMember(policy, memberName));
|
|
535
609
|
if (grantingPolicies.length === 0) {
|
|
536
610
|
cubeAccessDenied = true;
|
|
@@ -547,7 +621,7 @@ class CompilerApi {
|
|
|
547
621
|
policy.memberMasking.includesMembers.includes(memberName) &&
|
|
548
622
|
!policy.memberMasking.excludesMembers.includes(memberName));
|
|
549
623
|
if (hasMaskingPolicy) {
|
|
550
|
-
maskedMembersSet.add(
|
|
624
|
+
maskedMembersSet.add(queryMemberName);
|
|
551
625
|
const conditionalFullAccessPolicies = grantingPolicies.filter((policy) => {
|
|
552
626
|
const hasFullMemberAccess = !policy.memberLevel ||
|
|
553
627
|
(policy.memberLevel.includesMembers.includes(memberName) &&
|
|
@@ -556,7 +630,7 @@ class CompilerApi {
|
|
|
556
630
|
});
|
|
557
631
|
if (conditionalFullAccessPolicies.length > 0) {
|
|
558
632
|
const policyFilters = conditionalFullAccessPolicies.map(policyRowFilter);
|
|
559
|
-
memberMaskFiltersMap[
|
|
633
|
+
memberMaskFiltersMap[queryMemberName] = policyFilters.length === 1
|
|
560
634
|
? policyFilters[0]
|
|
561
635
|
: { or: policyFilters };
|
|
562
636
|
}
|
|
@@ -582,7 +656,9 @@ class CompilerApi {
|
|
|
582
656
|
query.segments = query.segments || [];
|
|
583
657
|
query.segments.push({
|
|
584
658
|
expression: () => '1 = 0',
|
|
585
|
-
|
|
659
|
+
// A cube reached only through an alias isn't in the join graph
|
|
660
|
+
// itself; the cube the alias is declared on is
|
|
661
|
+
cubeName: instancePath === cubeName ? cube.name : instancePath.split('.')[0],
|
|
586
662
|
name: 'rlsAccessDenied',
|
|
587
663
|
});
|
|
588
664
|
return { query, denied: true };
|
|
@@ -624,6 +700,25 @@ class CompilerApi {
|
|
|
624
700
|
}
|
|
625
701
|
return { query, denied: false };
|
|
626
702
|
}
|
|
703
|
+
/**
|
|
704
|
+
* Moves a filter on members of `cubeName` onto the cube instance at
|
|
705
|
+
* `instancePath`. Policy filters only name members of their own cube.
|
|
706
|
+
*/
|
|
707
|
+
rebaseFilterMembers(filter, cubeName, instancePath) {
|
|
708
|
+
if (!filter || typeof filter !== 'object') {
|
|
709
|
+
return filter;
|
|
710
|
+
}
|
|
711
|
+
const rebase = (member) => (typeof member === 'string' && member.startsWith(`${cubeName}.`) ?
|
|
712
|
+
`${instancePath}${member.slice(cubeName.length)}` : member);
|
|
713
|
+
const rebaseAll = (filters) => filters.map((f) => this.rebaseFilterMembers(f, cubeName, instancePath));
|
|
714
|
+
return {
|
|
715
|
+
...filter,
|
|
716
|
+
...(filter.member ? { member: rebase(filter.member) } : {}),
|
|
717
|
+
...(filter.dimension ? { dimension: rebase(filter.dimension) } : {}),
|
|
718
|
+
...(filter.and ? { and: rebaseAll(filter.and) } : {}),
|
|
719
|
+
...(filter.or ? { or: rebaseAll(filter.or) } : {}),
|
|
720
|
+
};
|
|
721
|
+
}
|
|
627
722
|
filterMemberName(filter) {
|
|
628
723
|
return filter?.member || filter?.dimension;
|
|
629
724
|
}
|
|
@@ -747,6 +842,93 @@ class CompilerApi {
|
|
|
747
842
|
const { cubeEvaluator } = await this.getCompilers();
|
|
748
843
|
return cubeEvaluator.preAggregations(filter);
|
|
749
844
|
}
|
|
845
|
+
/**
|
|
846
|
+
* The members each external rollup may serve, one array per rollup (views in their own
|
|
847
|
+
* names): cubesql plans a scan over a pre-aggregation only when its members fit one.
|
|
848
|
+
*/
|
|
849
|
+
async externalPreAggregationMembers() {
|
|
850
|
+
const compilers = await this.getCompilers();
|
|
851
|
+
// A failure only leaves the rollups unread by pushed down SQL, not the SQL API down
|
|
852
|
+
return compilers.compilerCache.cache(['externalPreAggregationMembers'], () => this.createQueryByDataSource(compilers, {})
|
|
853
|
+
.then((query) => this.collectExternalPreAggregationMembers(compilers.cubeEvaluator, query))
|
|
854
|
+
.catch((e) => {
|
|
855
|
+
this.logger('Pre-aggregation Members Error', { error: e.stack || e.message || e.toString() });
|
|
856
|
+
return [];
|
|
857
|
+
}));
|
|
858
|
+
}
|
|
859
|
+
collectExternalPreAggregationMembers(cubeEvaluator, query) {
|
|
860
|
+
const infos = cubeEvaluator.preAggregations({});
|
|
861
|
+
const byId = new Map(infos.map((info) => [info.id, info]));
|
|
862
|
+
const memberPath = (reference) => reference.split('.').slice(-2).join('.');
|
|
863
|
+
const membersOf = (info, seen) => {
|
|
864
|
+
const members = new Set();
|
|
865
|
+
if (seen.has(info.id)) {
|
|
866
|
+
return members;
|
|
867
|
+
}
|
|
868
|
+
seen.add(info.id);
|
|
869
|
+
const { references } = info;
|
|
870
|
+
[...references.dimensions, ...references.measures]
|
|
871
|
+
.forEach((reference) => members.add(memberPath(reference)));
|
|
872
|
+
references.timeDimensions.forEach(({ dimension }) => members.add(memberPath(dimension)));
|
|
873
|
+
references.rollups.forEach((rollup) => {
|
|
874
|
+
const referenced = byId.get(rollup);
|
|
875
|
+
if (referenced) {
|
|
876
|
+
membersOf(referenced, seen).forEach((member) => members.add(member));
|
|
877
|
+
}
|
|
878
|
+
});
|
|
879
|
+
return members;
|
|
880
|
+
};
|
|
881
|
+
const views = Object.entries(cubeEvaluator.evaluatedCubes)
|
|
882
|
+
.filter(([, cube]) => cube.isView && cube.includedMembers);
|
|
883
|
+
// Which cube members reference each member, directly or through other members:
|
|
884
|
+
// a calculated or multi-stage member can be served by a rollup holding what it reads
|
|
885
|
+
const referencedBy = new Map();
|
|
886
|
+
const cubes = Object.entries(cubeEvaluator.evaluatedCubes).filter(([, cube]) => !cube.isView);
|
|
887
|
+
for (const [cubeName, cube] of cubes) {
|
|
888
|
+
const members = [
|
|
889
|
+
...Object.keys(cube.measures || {}).map((name) => [`${cubeName}.${name}`, query.newMeasure(`${cubeName}.${name}`)]),
|
|
890
|
+
...Object.keys(cube.dimensions || {}).map((name) => [`${cubeName}.${name}`, query.newDimension(`${cubeName}.${name}`)]),
|
|
891
|
+
...Object.keys(cube.segments || {}).map((name) => [`${cubeName}.${name}`, query.newSegment(`${cubeName}.${name}`)]),
|
|
892
|
+
];
|
|
893
|
+
for (const [name, member] of members) {
|
|
894
|
+
let references = [];
|
|
895
|
+
try {
|
|
896
|
+
references = query.collectFrom([member], query.collectMemberNamesFor.bind(query), 'collectMemberNamesFor');
|
|
897
|
+
}
|
|
898
|
+
catch (e) {
|
|
899
|
+
this.logger('Pre-aggregation Member References Error', { member: name, error: e.message || e.toString() });
|
|
900
|
+
}
|
|
901
|
+
for (const reference of references.map(memberPath)) {
|
|
902
|
+
if (reference !== name) {
|
|
903
|
+
referencedBy.set(reference, (referencedBy.get(reference) || new Set()).add(name));
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
const addReferencingMembers = (members) => {
|
|
909
|
+
for (const member of members) {
|
|
910
|
+
(referencedBy.get(member) || []).forEach((referencing) => members.add(referencing));
|
|
911
|
+
}
|
|
912
|
+
};
|
|
913
|
+
const rollups = [];
|
|
914
|
+
const externalInfos = infos.filter((info) => info.preAggregation?.external);
|
|
915
|
+
for (const info of externalInfos) {
|
|
916
|
+
const members = membersOf(info, new Set());
|
|
917
|
+
if (members.size > 0) {
|
|
918
|
+
addReferencingMembers(members);
|
|
919
|
+
rollups.push([...members]);
|
|
920
|
+
for (const [viewName, view] of views) {
|
|
921
|
+
const viewMembers = view.includedMembers
|
|
922
|
+
.filter((member) => members.has(memberPath(member.memberPath)))
|
|
923
|
+
.map((member) => `${viewName}.${member.name}`);
|
|
924
|
+
if (viewMembers.length > 0) {
|
|
925
|
+
rollups.push(viewMembers);
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
return rollups;
|
|
931
|
+
}
|
|
750
932
|
async scheduledPreAggregations() {
|
|
751
933
|
const { cubeEvaluator } = await this.getCompilers();
|
|
752
934
|
return cubeEvaluator.scheduledPreAggregations();
|
|
@@ -767,7 +949,7 @@ class CompilerApi {
|
|
|
767
949
|
allowUngroupedWithoutPrimaryKey: this.allowUngroupedWithoutPrimaryKey,
|
|
768
950
|
convertTzForRawTimeDimension: this.convertTzForRawTimeDimension,
|
|
769
951
|
localRefreshKey: this.localRefreshKey,
|
|
770
|
-
queryFactory: this.queryFactory,
|
|
952
|
+
queryFactory: this.queryFactories.get(compilers) ?? this.queryFactory,
|
|
771
953
|
});
|
|
772
954
|
}
|
|
773
955
|
/**
|
|
@@ -896,7 +1078,7 @@ class CompilerApi {
|
|
|
896
1078
|
const { cubeEvaluator } = await this.getCompilers({ requestId: query.requestId });
|
|
897
1079
|
return cubeEvaluator
|
|
898
1080
|
.cubeNames()
|
|
899
|
-
.map((cube) => ({ [cube]: cubeEvaluator.
|
|
1081
|
+
.map((cube) => ({ [cube]: cubeEvaluator.cubeDataSource(cube) })).reduce((a, b) => ({ ...a, ...b }), {});
|
|
900
1082
|
}
|
|
901
1083
|
async memberToDataSource(query) {
|
|
902
1084
|
const { cubeEvaluator } = await this.getCompilers({ requestId: query.requestId });
|
|
@@ -908,14 +1090,12 @@ class CompilerApi {
|
|
|
908
1090
|
const viewName = cubeDef.name;
|
|
909
1091
|
return cubeDef.includedMembers?.map((included) => {
|
|
910
1092
|
const memberName = `${viewName}.${included.name}`;
|
|
911
|
-
|
|
912
|
-
const dataSource = refCubeDef.dataSource ?? 'default';
|
|
913
|
-
return [memberName, dataSource];
|
|
1093
|
+
return [memberName, cubeEvaluator.cubeDataSource(included.memberPath)];
|
|
914
1094
|
}) || [];
|
|
915
1095
|
}
|
|
916
1096
|
else {
|
|
917
1097
|
const cubeName = cubeDef.name;
|
|
918
|
-
const dataSource =
|
|
1098
|
+
const dataSource = cubeEvaluator.cubeDataSource(cubeName);
|
|
919
1099
|
return [
|
|
920
1100
|
...Object.keys(cubeDef.dimensions),
|
|
921
1101
|
...Object.keys(cubeDef.measures),
|