Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 36 additions & 31 deletions packages/cubejs-schema-compiler/src/adapter/BaseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}]
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
]
Expand Down
Loading