Skip to content

Commit 398fc4d

Browse files
committed
use shiftInterval even if timeShift is w/o timeDimension
1 parent 6d433ce commit 398fc4d

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,11 +1287,23 @@ export class BaseQuery {
12871287
if (memberDef.addGroupByReferences) {
12881288
queryContext = { ...queryContext, dimensions: R.uniq(queryContext.dimensions.concat(memberDef.addGroupByReferences)) };
12891289
}
1290-
if (memberDef.timeShiftReferences) {
1291-
queryContext = {
1292-
...queryContext,
1293-
timeDimensions: queryContext.timeDimensions.map(td => {
1294-
const timeShift = memberDef.timeShiftReferences?.find(r => r.timeDimension === td.dimension);
1290+
if (memberDef.timeShiftReferences?.length) {
1291+
let mapFn;
1292+
1293+
if (memberDef.timeShiftReferences.length === 1 && !memberDef.timeShiftReferences[0].timeDimension) {
1294+
const timeShift = memberDef.timeShiftReferences[0];
1295+
mapFn = (td) => {
1296+
if (td.shiftInterval) {
1297+
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}'`);
1298+
}
1299+
return {
1300+
...td,
1301+
shiftInterval: timeShift.type === 'next' ? this.negateInterval(timeShift.interval) : timeShift.interval
1302+
};
1303+
};
1304+
} else {
1305+
mapFn = (td) => {
1306+
const timeShift = memberDef.timeShiftReferences.find(r => r.timeDimension === td.dimension);
12951307
if (timeShift) {
12961308
if (td.shiftInterval) {
12971309
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}'`);
@@ -1302,7 +1314,12 @@ export class BaseQuery {
13021314
};
13031315
}
13041316
return td;
1305-
})
1317+
};
1318+
}
1319+
1320+
queryContext = {
1321+
...queryContext,
1322+
timeDimensions: queryContext.timeDimensions.map(mapFn)
13061323
};
13071324
}
13081325
queryContext = {

0 commit comments

Comments
 (0)