Skip to content

Commit ec4f4da

Browse files
committed
fill missing dateRanges for TDs
1 parent 337e2e7 commit ec4f4da

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,7 @@ class ApiGateway {
11711171
let queryType: QueryType = QueryTypeEnum.REGULAR_QUERY;
11721172
if (!Array.isArray(query)) {
11731173
query = this.compareDateRangeTransformer(query);
1174+
query = this.fillMissingDateRangesForTimeDimensions(query);
11741175
if (Array.isArray(query)) {
11751176
queryType = QueryTypeEnum.COMPARE_DATE_RANGE_QUERY;
11761177
}
@@ -2485,6 +2486,28 @@ class ApiGateway {
24852486
}
24862487
};
24872488

2489+
protected fillMissingDateRangesForTimeDimensions(query) {
2490+
if (!query.timeDimensions) {
2491+
return query;
2492+
}
2493+
2494+
const timeDimensionCount = query.timeDimensions.reduce((acc, item) => {
2495+
acc[item.dimension] = acc[item.dimension] || {};
2496+
if (!acc[item.dimension].dateRange && item.dateRange) {
2497+
acc[item.dimension].dateRange = item.dateRange;
2498+
}
2499+
return acc;
2500+
}, {});
2501+
2502+
query.timeDimensions.forEach(td => {
2503+
if (!td.dateRange && timeDimensionCount[td.dimension].dateRange) {
2504+
td.dateRange = timeDimensionCount[td.dimension].dateRange;
2505+
}
2506+
});
2507+
2508+
return query;
2509+
}
2510+
24882511
protected compareDateRangeTransformer(query) {
24892512
let queryCompareDateRange;
24902513
let compareDateRangeTDIndex;

0 commit comments

Comments
 (0)