Skip to content

Commit dad3057

Browse files
committed
remove old timeshift flow
1 parent be9bed8 commit dad3057

File tree

1 file changed

+15
-48
lines changed

1 file changed

+15
-48
lines changed

packages/cubejs-schema-compiler/src/adapter/BaseQuery.js

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,9 +1446,6 @@ export class BaseQuery {
14461446
queryContext = { ...queryContext, dimensions: R.uniq(queryContext.dimensions.concat(memberDef.addGroupByReferences)) };
14471447
}
14481448
if (memberDef.timeShiftReferences?.length) {
1449-
let mapFn;
1450-
1451-
const allBackAliasMembers = this.allBackAliasTimeDimensions();
14521449
let { commonTimeShift } = queryContext;
14531450
const timeShifts = queryContext.timeShifts || {};
14541451
const memberOfCube = !this.cubeEvaluator.cubeFromPath(memberPath).isView;
@@ -1459,49 +1456,15 @@ export class BaseQuery {
14591456
if (memberOfCube) {
14601457
commonTimeShift = timeShift.type === 'next' ? this.negateInterval(timeShift.interval) : timeShift.interval;
14611458
}
1462-
1463-
mapFn = (td) => {
1464-
// We need to ignore aliased td, because it will match and insert shiftInterval on first
1465-
// occurrence, but later during recursion it will hit the original td but shiftInterval will be
1466-
// present and simple check for td.shiftInterval will always result in error.
1467-
if (td.shiftInterval && !td.dimension === allBackAliasMembers[timeShift.timeDimension]) {
1468-
throw new UserError(`Hierarchical time shift is not supported but was provided for '${td.dimension}'. Parent time shift is '${td.shiftInterval}' and current is '${timeShift.interval}'`);
1469-
}
1470-
return {
1471-
...td,
1472-
shiftInterval: timeShift.type === 'next' ? this.negateInterval(timeShift.interval) : timeShift.interval
1473-
};
1474-
};
1475-
} else {
1459+
} else if (memberOfCube) {
14761460
// We avoid view's timeshift evaluation as there will be another round of underlying cube's member evaluation
1477-
if (memberOfCube) {
1478-
memberDef.timeShiftReferences.forEach((r) => {
1479-
timeShifts[r.timeDimension] = r.type === 'next' ? this.negateInterval(r.interval) : r.interval;
1480-
});
1481-
}
1482-
1483-
mapFn = (td) => {
1484-
const timeShift = memberDef.timeShiftReferences.find(r => r.timeDimension === td.dimension || td.dimension === allBackAliasMembers[r.timeDimension]);
1485-
if (timeShift) {
1486-
// We need to ignore aliased td, because it will match and insert shiftInterval on first
1487-
// occurrence, but later during recursion it will hit the original td but shiftInterval will be
1488-
// present and simple check for td.shiftInterval will always result in error.
1489-
if (td.shiftInterval && !td.dimension === allBackAliasMembers[timeShift.timeDimension]) {
1490-
throw new UserError(`Hierarchical time shift is not supported but was provided for '${td.dimension}'. Parent time shift is '${td.shiftInterval}' and current is '${timeShift.interval}'`);
1491-
}
1492-
return {
1493-
...td,
1494-
shiftInterval: timeShift.type === 'next' ? this.negateInterval(timeShift.interval) : timeShift.interval
1495-
};
1496-
}
1497-
return td;
1498-
};
1461+
memberDef.timeShiftReferences.forEach((r) => {
1462+
timeShifts[r.timeDimension] = r.type === 'next' ? this.negateInterval(r.interval) : r.interval;
1463+
});
14991464
}
15001465

15011466
queryContext = {
15021467
...queryContext,
1503-
// TODO: Switch to one more general flow with commonTimeShift + timeShifts ?
1504-
timeDimensions: queryContext.timeDimensions.map(mapFn),
15051468
commonTimeShift,
15061469
timeShifts,
15071470
};
@@ -2921,16 +2884,20 @@ export class BaseQuery {
29212884
return td.dimensionSql();
29222885
} else {
29232886
let res = this.autoPrefixAndEvaluateSql(cubeName, symbol.sql, isMemberExpr);
2924-
const mp = this.cubeEvaluator.pathFromArray([cubeName, name]);
2887+
const memPath = this.cubeEvaluator.pathFromArray([cubeName, name]);
29252888

29262889
// Skip view's member evaluation as there will be underlying cube's same member evaluation
2927-
if (symbol.type === 'time' && !this.cubeEvaluator.cubeFromPath(mp).isView) {
2928-
if (this.safeEvaluateSymbolContext().commonTimeShift) {
2890+
if (symbol.type === 'time' && !this.cubeEvaluator.cubeFromPath(memPath).isView) {
2891+
if (this.safeEvaluateSymbolContext().timeShifts?.[memPath]) {
2892+
if (symbol.shiftInterval) {
2893+
throw new UserError(`Hierarchical time shift is not supported but was provided for '${memPath}'. Parent time shift is '${symbol.shiftInterval}' and current is '${this.safeEvaluateSymbolContext().timeShifts?.[memPath]}'`);
2894+
}
2895+
res = `(${this.addTimestampInterval(res, this.safeEvaluateSymbolContext().timeShifts?.[memPath])})`;
2896+
} else if (this.safeEvaluateSymbolContext().commonTimeShift) {
2897+
if (symbol.shiftInterval) {
2898+
throw new UserError(`Hierarchical time shift is not supported but was provided for '${memPath}'. Parent time shift is '${symbol.shiftInterval}' and current is '${this.safeEvaluateSymbolContext().commonTimeShift}'`);
2899+
}
29292900
res = `(${this.addTimestampInterval(res, this.safeEvaluateSymbolContext().commonTimeShift)})`;
2930-
} else if (this.safeEvaluateSymbolContext().timeShifts?.[this.cubeEvaluator.pathFromArray([cubeName, name])]) {
2931-
res = `(${this.addTimestampInterval(res, this.safeEvaluateSymbolContext().timeShifts?.[this.cubeEvaluator.pathFromArray([cubeName, name])])})`;
2932-
} else if (symbol.shiftInterval) {
2933-
res = `(${this.addTimestampInterval(res, symbol.shiftInterval)})`;
29342901
}
29352902
}
29362903

0 commit comments

Comments
 (0)