Skip to content

Commit

Permalink
fill missing dateRanges for TDs
Browse files Browse the repository at this point in the history
  • Loading branch information
KSDaemon committed Jan 22, 2025
1 parent 0dd13c6 commit 5657e2b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/cubejs-api-gateway/src/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,7 @@ class ApiGateway {
let queryType: QueryType = QueryTypeEnum.REGULAR_QUERY;
if (!Array.isArray(query)) {
query = this.compareDateRangeTransformer(query);
query = this.fillMissingDateRangesForTimeDimensions(query);
if (Array.isArray(query)) {
queryType = QueryTypeEnum.COMPARE_DATE_RANGE_QUERY;
}
Expand Down Expand Up @@ -2446,6 +2447,28 @@ class ApiGateway {
}
};

protected fillMissingDateRangesForTimeDimensions(query) {
if (!query.timeDimensions) {
return query;
}

const timeDimensionCount = query.timeDimensions.reduce((acc, item) => {
acc[item.dimension] = acc[item.dimension] || {};
if (!acc[item.dimension].dateRange && item.dateRange) {
acc[item.dimension].dateRange = item.dateRange;
}
return acc;
}, {});

query.timeDimensions.forEach(td => {
if (!td.dateRange && timeDimensionCount[td.dimension].dateRange) {
td.dateRange = timeDimensionCount[td.dimension].dateRange;
}
});

return query;
}

protected compareDateRangeTransformer(query) {
let queryCompareDateRange;
let compareDateRangeTDIndex;
Expand Down

0 comments on commit 5657e2b

Please sign in to comment.