@cubejs-backend/schema-compiler 1.8.5 → 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/adapter/BaseDimension.d.ts +10 -0
- package/dist/src/adapter/BaseDimension.d.ts.map +1 -1
- package/dist/src/adapter/BaseDimension.js +18 -3
- package/dist/src/adapter/BaseDimension.js.map +1 -1
- package/dist/src/adapter/BaseFilter.d.ts.map +1 -1
- package/dist/src/adapter/BaseFilter.js +5 -1
- package/dist/src/adapter/BaseFilter.js.map +1 -1
- package/dist/src/adapter/BaseMeasure.d.ts +10 -0
- package/dist/src/adapter/BaseMeasure.d.ts.map +1 -1
- package/dist/src/adapter/BaseMeasure.js +18 -3
- package/dist/src/adapter/BaseMeasure.js.map +1 -1
- package/dist/src/adapter/BaseQuery.d.ts +53 -2
- package/dist/src/adapter/BaseQuery.d.ts.map +1 -1
- package/dist/src/adapter/BaseQuery.js +148 -8
- package/dist/src/adapter/BaseQuery.js.map +1 -1
- package/dist/src/adapter/BaseSegment.d.ts +1 -0
- package/dist/src/adapter/BaseSegment.d.ts.map +1 -1
- package/dist/src/adapter/BaseSegment.js +4 -2
- package/dist/src/adapter/BaseSegment.js.map +1 -1
- package/dist/src/adapter/BaseTimeDimension.d.ts +5 -0
- package/dist/src/adapter/BaseTimeDimension.d.ts.map +1 -1
- package/dist/src/adapter/BaseTimeDimension.js +10 -2
- package/dist/src/adapter/BaseTimeDimension.js.map +1 -1
- package/dist/src/adapter/Granularity.js +1 -1
- package/dist/src/adapter/Granularity.js.map +1 -1
- package/dist/src/adapter/MssqlQuery.d.ts.map +1 -1
- package/dist/src/adapter/MssqlQuery.js +4 -0
- package/dist/src/adapter/MssqlQuery.js.map +1 -1
- package/dist/src/adapter/PreAggregations.d.ts +1 -0
- package/dist/src/adapter/PreAggregations.d.ts.map +1 -1
- package/dist/src/adapter/PreAggregations.js +20 -14
- package/dist/src/adapter/PreAggregations.js.map +1 -1
- package/dist/src/adapter/QueryFactory.d.ts +7 -3
- package/dist/src/adapter/QueryFactory.d.ts.map +1 -1
- package/dist/src/adapter/QueryFactory.js +10 -9
- package/dist/src/adapter/QueryFactory.js.map +1 -1
- package/dist/src/adapter/index.d.ts +2 -1
- package/dist/src/adapter/index.d.ts.map +1 -1
- package/dist/src/adapter/index.js +1 -0
- package/dist/src/adapter/index.js.map +1 -1
- package/dist/src/compiler/CubeEvaluator.d.ts +21 -0
- package/dist/src/compiler/CubeEvaluator.d.ts.map +1 -1
- package/dist/src/compiler/CubeEvaluator.js +143 -49
- package/dist/src/compiler/CubeEvaluator.js.map +1 -1
- package/dist/src/compiler/CubeSymbols.d.ts +32 -2
- package/dist/src/compiler/CubeSymbols.d.ts.map +1 -1
- package/dist/src/compiler/CubeSymbols.js +127 -21
- package/dist/src/compiler/CubeSymbols.js.map +1 -1
- package/dist/src/compiler/CubeValidator.d.ts.map +1 -1
- package/dist/src/compiler/CubeValidator.js +11 -1
- package/dist/src/compiler/CubeValidator.js.map +1 -1
- package/dist/src/compiler/DataSchemaCompiler.d.ts.map +1 -1
- package/dist/src/compiler/DataSchemaCompiler.js +9 -1
- package/dist/src/compiler/DataSchemaCompiler.js.map +1 -1
- package/dist/src/compiler/JoinGraph.d.ts +5 -3
- package/dist/src/compiler/JoinGraph.d.ts.map +1 -1
- package/dist/src/compiler/JoinGraph.js +101 -19
- package/dist/src/compiler/JoinGraph.js.map +1 -1
- package/dist/src/compiler/index.d.ts +2 -2
- package/dist/src/compiler/index.d.ts.map +1 -1
- package/package.json +7 -7
|
@@ -138,7 +138,7 @@ class BaseQuery {
|
|
|
138
138
|
else if (!f.member && !f.dimension) {
|
|
139
139
|
throw new UserError_1.UserError(`member attribute is required for filter ${JSON.stringify(f)}`);
|
|
140
140
|
}
|
|
141
|
-
else if (this.
|
|
141
|
+
else if (this.isMeasurePath(f.member || f.dimension)) {
|
|
142
142
|
allFilters.push({ measure: f.member || f.dimension });
|
|
143
143
|
}
|
|
144
144
|
else {
|
|
@@ -203,7 +203,7 @@ class BaseQuery {
|
|
|
203
203
|
if (!f.member && !f.dimension) {
|
|
204
204
|
throw new UserError_1.UserError(`member attribute is required for filter ${JSON.stringify(f)}`);
|
|
205
205
|
}
|
|
206
|
-
if (this.
|
|
206
|
+
if (this.isMeasurePath(f.member || f.dimension)) {
|
|
207
207
|
return Object.assign({}, f, {
|
|
208
208
|
dimension: null,
|
|
209
209
|
measure: f.member || f.dimension
|
|
@@ -585,11 +585,32 @@ class BaseQuery {
|
|
|
585
585
|
return dataSources[0];
|
|
586
586
|
}
|
|
587
587
|
cubeDataSource(cube) {
|
|
588
|
-
return this.cubeEvaluator.
|
|
588
|
+
return this.cubeEvaluator.cubeDataSource(cube);
|
|
589
589
|
}
|
|
590
590
|
get aliasNameToMember() {
|
|
591
|
-
return ramda_1.default.fromPairs(this.measures.map(m => [m.unescapedAliasName(), m.
|
|
592
|
-
.map(m => [m.unescapedAliasName(), `${m.
|
|
591
|
+
return ramda_1.default.fromPairs(this.measures.map(m => [m.unescapedAliasName(), m.memberPath()]).concat(this.dimensions.map(m => [m.unescapedAliasName(), m.memberPath()])).concat(this.timeDimensions.filter(m => !!m.granularity)
|
|
592
|
+
.map(m => [m.unescapedAliasName(), `${m.memberPath()}.${m.granularity}`])));
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Splits a member path into the data-model member and the join hint to it.
|
|
596
|
+
* Through a join alias the model knows the member by its target path, and the
|
|
597
|
+
* path itself names the member's output.
|
|
598
|
+
* @param {string} path
|
|
599
|
+
* @returns {{ path: string, joinHint: string[], aliasPath?: string }}
|
|
600
|
+
*/
|
|
601
|
+
memberPathForModel(path) {
|
|
602
|
+
const resolved = this.cubeEvaluator.resolveMemberPath(path);
|
|
603
|
+
if (resolved?.aliased) {
|
|
604
|
+
this.ensureNativePlannerForJoinAliases(path);
|
|
605
|
+
}
|
|
606
|
+
if (resolved?.aliased && !resolved.granularity) {
|
|
607
|
+
return { path: resolved.targetPath, joinHint: [], aliasPath: resolved.fullPath };
|
|
608
|
+
}
|
|
609
|
+
return CubeSymbols_1.CubeSymbols.joinHintFromPath(path);
|
|
610
|
+
}
|
|
611
|
+
isMeasurePath(path) {
|
|
612
|
+
const resolved = this.cubeEvaluator.resolveMemberPath(path);
|
|
613
|
+
return this.cubeEvaluator.isMeasure(resolved?.targetPath ?? path);
|
|
593
614
|
}
|
|
594
615
|
initUngrouped() {
|
|
595
616
|
this.ungrouped = this.options.ungrouped;
|
|
@@ -2360,10 +2381,14 @@ class BaseQuery {
|
|
|
2360
2381
|
* @param {boolean} excludeTimeDimensions
|
|
2361
2382
|
* @param {(t: () => void) => T} fn
|
|
2362
2383
|
* @param {string | Array<string>} methodName
|
|
2384
|
+
* @param {(member: unknown) => boolean} [memberFilter]
|
|
2363
2385
|
* @returns {T}
|
|
2364
2386
|
*/
|
|
2365
|
-
collectFromMembers(excludeTimeDimensions, fn, methodName) {
|
|
2366
|
-
const
|
|
2387
|
+
collectFromMembers(excludeTimeDimensions, fn, methodName, memberFilter) {
|
|
2388
|
+
const members = this.allMembersConcat(excludeTimeDimensions);
|
|
2389
|
+
const membersToCollectFrom = (memberFilter ?
|
|
2390
|
+
[{ getMembers: () => ramda_1.default.flatten(members.map(m => m.getMembers())).filter(memberFilter) }] :
|
|
2391
|
+
members)
|
|
2367
2392
|
.concat(this.join ? this.join.joins.map(j => ({
|
|
2368
2393
|
getMembers: () => [{
|
|
2369
2394
|
path: () => null,
|
|
@@ -2706,6 +2731,19 @@ class BaseQuery {
|
|
|
2706
2731
|
}
|
|
2707
2732
|
}
|
|
2708
2733
|
pushMemberNameForCollectionIfNecessary(cubeName, name) {
|
|
2734
|
+
// A member of a cube instance: the planner joins the instance itself, so
|
|
2735
|
+
// only the cube it instantiates is collected, and the member under its path
|
|
2736
|
+
const instance = this.safeEvaluateSymbolContext().memberInstance;
|
|
2737
|
+
if (instance) {
|
|
2738
|
+
this.pushCubeNameForCollectionIfNecessary(cubeName);
|
|
2739
|
+
const context = this.safeEvaluateSymbolContext();
|
|
2740
|
+
if (context.memberNames && name) {
|
|
2741
|
+
context.memberNames.push(context.instanceMemberNames ?
|
|
2742
|
+
this.instanceMemberName(instance, cubeName, name) :
|
|
2743
|
+
this.cubeEvaluator.pathFromArray([cubeName, name]));
|
|
2744
|
+
}
|
|
2745
|
+
return;
|
|
2746
|
+
}
|
|
2709
2747
|
const pathFromArray = this.cubeEvaluator.pathFromArray([cubeName, name]);
|
|
2710
2748
|
if (!this.cubeEvaluator.getCubeDefinition(cubeName).isView) {
|
|
2711
2749
|
const joinHints = this.cubeEvaluator.joinHints();
|
|
@@ -2727,6 +2765,15 @@ class BaseQuery {
|
|
|
2727
2765
|
return this.evaluateSymbolContext || {};
|
|
2728
2766
|
}
|
|
2729
2767
|
evaluateSymbolSql(cubeName, name, symbol, memberExpressionType, subPropertyName) {
|
|
2768
|
+
const aliasPath = this.cubeEvaluator.joinAliasPath();
|
|
2769
|
+
if (aliasPath && this.safeEvaluateSymbolContext().memberInstanceAliasPath !== aliasPath) {
|
|
2770
|
+
this.ensureNativePlannerForJoinAliases([...aliasPath, name].join('.'));
|
|
2771
|
+
return this.evaluateSymbolSqlWithContext(() => this.evaluateSymbolSql(cubeName, name, symbol, memberExpressionType, subPropertyName), { memberInstance: this.aliasedMemberInstance(aliasPath, cubeName), memberInstanceAliasPath: aliasPath });
|
|
2772
|
+
}
|
|
2773
|
+
const joinedInstance = this.joinedMemberInstance(cubeName);
|
|
2774
|
+
if (joinedInstance) {
|
|
2775
|
+
return this.evaluateSymbolSqlWithContext(() => this.evaluateSymbolSql(cubeName, name, symbol, memberExpressionType, subPropertyName), { memberInstance: joinedInstance });
|
|
2776
|
+
}
|
|
2730
2777
|
const isMemberExpr = !!memberExpressionType;
|
|
2731
2778
|
if (!memberExpressionType) {
|
|
2732
2779
|
this.pushMemberNameForCollectionIfNecessary(cubeName, name);
|
|
@@ -3127,8 +3174,87 @@ class BaseQuery {
|
|
|
3127
3174
|
this.evaluateSymbolSqlWithContext(fn, context);
|
|
3128
3175
|
return ramda_1.default.uniq(context.memberNames);
|
|
3129
3176
|
}
|
|
3177
|
+
/**
|
|
3178
|
+
* Only the Tesseract planner joins cube instances reached through a join alias.
|
|
3179
|
+
*/
|
|
3180
|
+
ensureNativePlannerForJoinAliases(path) {
|
|
3181
|
+
if (!(this.options.useNativeSqlPlanner ?? (0, shared_1.getEnv)('nativeSqlPlanner'))) {
|
|
3182
|
+
throw new UserError_1.UserError(`'${path}' goes through a join alias, and join aliases require the Tesseract SQL planner`);
|
|
3183
|
+
}
|
|
3184
|
+
}
|
|
3185
|
+
/**
|
|
3186
|
+
* Names of the members the query reads. A member of a cube instance is named
|
|
3187
|
+
* by its path through the join alias, so policies can tell instances apart.
|
|
3188
|
+
*/
|
|
3130
3189
|
collectAllMemberNames() {
|
|
3131
|
-
return
|
|
3190
|
+
return this.evaluateSymbolSqlWithContext(() => this.collectAllMemberNamesInContext(), { instanceMemberNames: true });
|
|
3191
|
+
}
|
|
3192
|
+
collectAllMemberNamesInContext() {
|
|
3193
|
+
const leaves = ramda_1.default.flatten(this.allMembersConcat(false).map(m => m.getMembers()));
|
|
3194
|
+
const aliased = leaves.filter(m => m.aliasPath);
|
|
3195
|
+
const names = aliased.length ?
|
|
3196
|
+
ramda_1.default.flatten(this.collectFromMembers(false, this.collectMemberNamesFor.bind(this), 'collectAllMemberNames', m => !m.aliasPath)) :
|
|
3197
|
+
ramda_1.default.flatten(this.collectFromMembers(false, this.collectMemberNamesFor.bind(this), 'collectAllMemberNames'));
|
|
3198
|
+
return ramda_1.default.uniq(names.concat(aliased.flatMap(member => {
|
|
3199
|
+
const resolved = this.cubeEvaluator.resolveMemberPath(member.aliasPath);
|
|
3200
|
+
return this.evaluateSymbolSqlWithContext(() => ramda_1.default.flatten(this.collectFrom([member], this.collectMemberNamesFor.bind(this), ['collectAllMemberNames', member.aliasPath])), { memberInstance: { path: resolved.instancePath, cube: resolved.targetCube } });
|
|
3201
|
+
})));
|
|
3202
|
+
}
|
|
3203
|
+
/**
|
|
3204
|
+
* The cube instance a member of `cubeName` read inside the instance being
|
|
3205
|
+
* evaluated belongs to, when the reference reaches `cubeName` through joins
|
|
3206
|
+
* without an alias: every join below an alias reaches an instance of its own.
|
|
3207
|
+
*/
|
|
3208
|
+
joinedMemberInstance(cubeName) {
|
|
3209
|
+
const instance = this.safeEvaluateSymbolContext().memberInstance;
|
|
3210
|
+
if (!instance || instance.cube === cubeName) {
|
|
3211
|
+
return undefined;
|
|
3212
|
+
}
|
|
3213
|
+
const hints = this.cubeEvaluator.joinHints() || [];
|
|
3214
|
+
const steps = hints[hints.length - 1] === cubeName ? hints : [cubeName];
|
|
3215
|
+
let current = instance;
|
|
3216
|
+
for (const step of steps) {
|
|
3217
|
+
if (step !== current.cube) {
|
|
3218
|
+
if (!this.cubeEvaluator.joinsWithoutAlias(current.cube, step)) {
|
|
3219
|
+
return undefined;
|
|
3220
|
+
}
|
|
3221
|
+
current = { path: `${current.path}.${step}`, cube: step };
|
|
3222
|
+
}
|
|
3223
|
+
}
|
|
3224
|
+
return current;
|
|
3225
|
+
}
|
|
3226
|
+
/**
|
|
3227
|
+
* The name of a member read inside the cube instance `instance`: the
|
|
3228
|
+
* instance's own cube and the cubes that cube joins directly belong to it.
|
|
3229
|
+
*/
|
|
3230
|
+
instanceMemberName(instance, cubeName, name) {
|
|
3231
|
+
if (cubeName === instance.cube) {
|
|
3232
|
+
return `${instance.path}.${name}`;
|
|
3233
|
+
}
|
|
3234
|
+
const joins = this.cubeEvaluator.cubeFromPath(instance.cube).joins || [];
|
|
3235
|
+
if (joins.some(j => (j.alias ?? j.name) === cubeName)) {
|
|
3236
|
+
return `${instance.path}.${cubeName}.${name}`;
|
|
3237
|
+
}
|
|
3238
|
+
return this.cubeEvaluator.pathFromArray([cubeName, name]);
|
|
3239
|
+
}
|
|
3240
|
+
/**
|
|
3241
|
+
* The cube instance a reference through a join alias reaches, from inside
|
|
3242
|
+
* the instance being evaluated, if any.
|
|
3243
|
+
*/
|
|
3244
|
+
aliasedMemberInstance(aliasPath, cubeName) {
|
|
3245
|
+
const outer = this.safeEvaluateSymbolContext().memberInstance;
|
|
3246
|
+
if (!outer) {
|
|
3247
|
+
return { path: aliasPath.join('.'), cube: cubeName };
|
|
3248
|
+
}
|
|
3249
|
+
if (aliasPath[0] === outer.cube) {
|
|
3250
|
+
return { path: [outer.path, ...aliasPath.slice(1)].join('.'), cube: cubeName };
|
|
3251
|
+
}
|
|
3252
|
+
const joins = this.cubeEvaluator.cubeFromPath(outer.cube).joins || [];
|
|
3253
|
+
const joinedDirectly = joins.some(j => (j.alias ?? j.name) === aliasPath[0]);
|
|
3254
|
+
return {
|
|
3255
|
+
path: (joinedDirectly ? [outer.path, ...aliasPath] : aliasPath).join('.'),
|
|
3256
|
+
cube: cubeName,
|
|
3257
|
+
};
|
|
3132
3258
|
}
|
|
3133
3259
|
collectMultipliedMeasures(context) {
|
|
3134
3260
|
return (fn) => {
|
|
@@ -3493,6 +3619,17 @@ class BaseQuery {
|
|
|
3493
3619
|
if (this.options.memberToAlias && this.options.memberToAlias[name]) {
|
|
3494
3620
|
return this.options.memberToAlias[name];
|
|
3495
3621
|
}
|
|
3622
|
+
return this.canonicalAliasName(name, isPreAggregationName);
|
|
3623
|
+
}
|
|
3624
|
+
/**
|
|
3625
|
+
* Alias of a member when the query asks for none (`memberToAlias`). A pre-aggregation
|
|
3626
|
+
* table is built by a query asking for none, so its columns go by these names however
|
|
3627
|
+
* the query reading it aliases its own output.
|
|
3628
|
+
* @param {string} name Property name.
|
|
3629
|
+
* @param {boolean?} isPreAggregationName Pre-agg flag.
|
|
3630
|
+
* @returns {string}
|
|
3631
|
+
*/
|
|
3632
|
+
canonicalAliasName(name, isPreAggregationName = false) {
|
|
3496
3633
|
const path = name.split('.');
|
|
3497
3634
|
if (path[0] && this.cubeEvaluator.cubeExists(path[0]) && this.cubeEvaluator.cubeFromPath(path[0]).sqlAlias) {
|
|
3498
3635
|
const cubeName = path[0];
|
|
@@ -4665,6 +4802,9 @@ class BaseQuery {
|
|
|
4665
4802
|
memberChildren: undefined,
|
|
4666
4803
|
inlineWhereConditions: undefined,
|
|
4667
4804
|
collectOriginalSqlPreAggregations: undefined,
|
|
4805
|
+
instanceMemberNames: undefined,
|
|
4806
|
+
memberInstance: undefined,
|
|
4807
|
+
memberInstanceAliasPath: undefined,
|
|
4668
4808
|
});
|
|
4669
4809
|
const memberPath = member.expressionPath();
|
|
4670
4810
|
let nonAliasSeen = false;
|