diff --git a/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js b/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js index 58737882810a3..712f7347eed2a 100644 --- a/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js +++ b/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js @@ -945,45 +945,50 @@ export class BaseQuery { } runningTotalDateJoinCondition() { - return this.timeDimensions.map( - d => [ - d, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - (dateFrom, dateTo, dateField, dimensionDateFrom, dimensionDateTo) => `${dateField} >= ${dimensionDateFrom} AND ${dateField} <= ${dateTo}` - ] - ); + return this.timeDimensions + .map( + d => [ + d, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + (dateFrom, dateTo, dateField, dimensionDateFrom, dimensionDateTo) => `${dateField} >= ${dimensionDateFrom} AND ${dateField} <= ${dateTo}` + ] + ); } rollingWindowToDateJoinCondition(granularity) { - return this.timeDimensions.map( - d => [ - d, - (dateFrom, dateTo, dateField, dimensionDateFrom, dimensionDateTo, isFromStartToEnd) => `${dateField} >= ${this.timeGroupedColumn(granularity, dateFrom)} AND ${dateField} <= ${dateTo}` - ] - ); + return this.timeDimensions + .filter(td => td.granularity) + .map( + d => [ + d, + (dateFrom, dateTo, dateField, dimensionDateFrom, dimensionDateTo, isFromStartToEnd) => `${dateField} >= ${this.timeGroupedColumn(granularity, dateFrom)} AND ${dateField} <= ${dateTo}` + ] + ); } rollingWindowDateJoinCondition(trailingInterval, leadingInterval, offset) { offset = offset || 'end'; - return this.timeDimensions.map( - d => [d, (dateFrom, dateTo, dateField, dimensionDateFrom, dimensionDateTo, isFromStartToEnd) => { + return this.timeDimensions + .filter(td => td.granularity) + .map( + d => [d, (dateFrom, dateTo, dateField, dimensionDateFrom, dimensionDateTo, isFromStartToEnd) => { // dateFrom based window - const conditions = []; - if (trailingInterval !== 'unbounded') { - const startDate = isFromStartToEnd || offset === 'start' ? dateFrom : dateTo; - const trailingStart = trailingInterval ? this.subtractInterval(startDate, trailingInterval) : startDate; - const sign = offset === 'start' ? '>=' : '>'; - conditions.push(`${dateField} ${sign} ${trailingStart}`); - } - if (leadingInterval !== 'unbounded') { - const endDate = isFromStartToEnd || offset === 'end' ? dateTo : dateFrom; - const leadingEnd = leadingInterval ? this.addInterval(endDate, leadingInterval) : endDate; - const sign = offset === 'end' ? '<=' : '<'; - conditions.push(`${dateField} ${sign} ${leadingEnd}`); - } - return conditions.length ? conditions.join(' AND ') : '1 = 1'; - }] - ); + const conditions = []; + if (trailingInterval !== 'unbounded') { + const startDate = isFromStartToEnd || offset === 'start' ? dateFrom : dateTo; + const trailingStart = trailingInterval ? this.subtractInterval(startDate, trailingInterval) : startDate; + const sign = offset === 'start' ? '>=' : '>'; + conditions.push(`${dateField} ${sign} ${trailingStart}`); + } + if (leadingInterval !== 'unbounded') { + const endDate = isFromStartToEnd || offset === 'end' ? dateTo : dateFrom; + const leadingEnd = leadingInterval ? this.addInterval(endDate, leadingInterval) : endDate; + const sign = offset === 'end' ? '<=' : '<'; + conditions.push(`${dateField} ${sign} ${leadingEnd}`); + } + return conditions.length ? conditions.join(' AND ') : '1 = 1'; + }] + ); } /** diff --git a/packages/cubejs-testing/test/__snapshots__/birdbox-postgresql-pre-aggregations.test.ts.snap b/packages/cubejs-testing/test/__snapshots__/birdbox-postgresql-pre-aggregations.test.ts.snap index aa6dbc4729a9c..2c460f3a54246 100644 --- a/packages/cubejs-testing/test/__snapshots__/birdbox-postgresql-pre-aggregations.test.ts.snap +++ b/packages/cubejs-testing/test/__snapshots__/birdbox-postgresql-pre-aggregations.test.ts.snap @@ -5,7 +5,7 @@ exports[`postgresql-cubestore HTTP Transport Empty partitions: Empty partitions exports[`postgresql-cubestore HTTP Transport Rolling Mixed With Dimension No Granularity: Rolling Mixed With Dimension No Granularity 1`] = ` Array [ Object { - "visitors.checkinsRollingTotal": null, + "visitors.checkinsRollingTotal": "5", "visitors.source": "some", }, ] diff --git a/packages/cubejs-testing/test/__snapshots__/cli-postgresql-pre-aggregations.test.ts.snap b/packages/cubejs-testing/test/__snapshots__/cli-postgresql-pre-aggregations.test.ts.snap index 3c28478f95231..c08bfb0cae46b 100644 --- a/packages/cubejs-testing/test/__snapshots__/cli-postgresql-pre-aggregations.test.ts.snap +++ b/packages/cubejs-testing/test/__snapshots__/cli-postgresql-pre-aggregations.test.ts.snap @@ -5,7 +5,7 @@ exports[`postgresql HTTP Transport Empty partitions: Empty partitions 1`] = `Arr exports[`postgresql HTTP Transport Rolling Mixed With Dimension No Granularity: Rolling Mixed With Dimension No Granularity 1`] = ` Array [ Object { - "visitors.checkinsRollingTotal": null, + "visitors.checkinsRollingTotal": "5", "visitors.source": "some", }, ]