diff --git a/packages/cubejs-schema-compiler/adapter/BaseQuery.js b/packages/cubejs-schema-compiler/adapter/BaseQuery.js index 1541cb6996ec6..7779586af132a 100644 --- a/packages/cubejs-schema-compiler/adapter/BaseQuery.js +++ b/packages/cubejs-schema-compiler/adapter/BaseQuery.js @@ -312,6 +312,14 @@ class BaseQuery { return `${date} + interval '${interval}'`; } + addTimestampInterval(timestamp, interval) { + return this.addInterval(timestamp, interval); + } + + subtractTimestampInterval(timestamp, interval) { + return this.subtractInterval(timestamp, interval); + } + cumulativeMeasures() { return this.measures.filter(m => m.isCumulative()); } @@ -1530,7 +1538,7 @@ class BaseQuery { query.timeDimensions[0].path()[0] ][ query.timeDimensions[0].path()[1] - ].filter((from, to) => `${query.nowTimestampSql()} < ${updateWindow ? this.addInterval(this.timeStampCast(to), updateWindow) : this.timeStampCast(to)}`), + ].filter((from, to) => `${query.nowTimestampSql()} < ${updateWindow ? this.addTimestampInterval(this.timeStampCast(to), updateWindow) : this.timeStampCast(to)}`), label: originalRefreshKey }]) ); diff --git a/packages/cubejs-schema-compiler/adapter/BigqueryQuery.js b/packages/cubejs-schema-compiler/adapter/BigqueryQuery.js index 17a663b6eb0ab..24f229b505266 100644 --- a/packages/cubejs-schema-compiler/adapter/BigqueryQuery.js +++ b/packages/cubejs-schema-compiler/adapter/BigqueryQuery.js @@ -94,6 +94,14 @@ class BigqueryQuery extends BaseQuery { return `DATETIME_ADD(${date}, INTERVAL ${interval})`; } + subtractTimestampInterval(date, interval) { + return `TIMESTAMP_SUB(${date}, INTERVAL ${interval})`; + } + + addTimestampInterval(date, interval) { + return `TIMESTAMP_ADD(${date}, INTERVAL ${interval})`; + } + nowTimestampSql() { return `CURRENT_TIMESTAMP()`; }