Skip to content

Commit 79bf9c4

Browse files
committed
feat(tesseract): Rolling window with custom granularities without date range
1 parent 93a4dcb commit 79bf9c4

File tree

22 files changed

+164
-56
lines changed

22 files changed

+164
-56
lines changed

packages/cubejs-backend-shared/src/time.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export function parseSqlInterval(intervalStr: SqlInterval): ParsedInterval {
107107
const unit = parts[i + 1];
108108

109109
// Remove ending 's' (e.g., 'days' -> 'day')
110-
const singularUnit = (unit.endsWith('s') ? unit.slice(0, -1) : unit) as unitOfTime.DurationConstructor;
110+
const singularUnit = ((unit.endsWith('s') ? unit.slice(0, -1) : unit).toLowerCase()) as unitOfTime.DurationConstructor;
111111
interval[singularUnit] = value;
112112
}
113113

packages/cubejs-schema-compiler/src/adapter/BaseQuery.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2048,7 +2048,6 @@ export class BaseQuery {
20482048
* Returns a tuple: (formatted interval, minimal time unit)
20492049
*/
20502050
intervalAndMinimalTimeUnit(interval) {
2051-
const intervalParsed = parseSqlInterval(interval);
20522051
const minGranularity = this.diffTimeUnitForInterval(interval);
20532052
return [interval, minGranularity];
20542053
}

packages/cubejs-schema-compiler/src/adapter/BigqueryQuery.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,10 @@ export class BigqueryQuery extends BaseQuery {
127127
return [`'${intervalParsed.hour}:${intervalParsed.minute}:${intervalParsed.second}' HOUR TO SECOND`, 'SECOND'];
128128
} else if (intervalParsed.minute && intervalParsed.second && intKeys === 2) {
129129
return [`'${intervalParsed.minute}:${intervalParsed.second}' MINUTE TO SECOND`, 'SECOND'];
130+
} else if (intervalParsed.millisecond && intKeys === 1) {
131+
return [`'${intervalParsed.millisecond}' MILLISECOND`, 'MILLISECOND'];
130132
}
131133

132-
// No need to support microseconds.
133134

134135
throw new Error(`Cannot transform interval expression "${interval}" to BigQuery dialect`);
135136
}

packages/cubejs-schema-compiler/src/adapter/PostgresQuery.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@ export class PostgresQuery extends BaseQuery {
8181
templates.types.float = 'REAL';
8282
templates.types.double = 'DOUBLE PRECISION';
8383
templates.types.binary = 'BYTEA';
84+
templates.tesseract.support_generated_series_for_custom_td = 'YES';
8485
templates.operators.is_not_distinct_from = 'IS NOT DISTINCT FROM';
85-
templates.statements.generated_time_series_select = 'SELECT d AS "date_from",\n' +
86-
'd + interval {{ granularity }} - interval \'1 millisecond\' AS "date_to" \n' +
86+
templates.statements.generated_time_series_select = 'SELECT {{ date_from }} AS "date_from",\n' +
87+
'{{ date_to }} AS "date_to" \n' +
88+
//'d + interval {{ granularity }} - interval \'1 millisecond\' AS "date_to" \n' +
8789
'FROM generate_series({{ start }}::timestamp, {{ end }}:: timestamp, {{ granularity }}::interval) d ';
8890
templates.statements.generated_time_series_with_cte_range_source = 'SELECT d AS "date_from",\n' +
8991
'd + interval {{ granularity }} - interval \'1 millisecond\' AS "date_to" \n' +

packages/cubejs-schema-compiler/src/adapter/PrestodbQuery.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ export class PrestodbQuery extends BaseQuery {
155155
// Presto intervals have a YearMonth or DayTime type variants, but no universal type
156156
delete templates.types.interval;
157157
templates.types.binary = 'VARBINARY';
158+
templates.tesseract.support_generated_series_for_custom_td = "YES";
158159
templates.tesseract.ilike = 'LOWER({{ expr }}) {% if negated %}NOT {% endif %} LIKE {{ pattern }}';
159160
templates.filters.like_pattern = 'CONCAT({% if start_wild %}\'%\'{% else %}\'\'{% endif %}, LOWER({{ value }}), {% if end_wild %}\'%\'{% else %}\'\'{% endif %}) ESCAPE \'\\\'';
160161
templates.statements.time_series_select = 'SELECT from_iso8601_timestamp(dates.f) date_from, from_iso8601_timestamp(dates.t) date_to \n' +

packages/cubejs-testing-drivers/fixtures/athena.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,6 @@
185185
"querying custom granularities ECommerce: count by three_months_by_march + dimension",
186186
"querying custom granularities (with preaggregation) ECommerce: totalQuantity by half_year + no dimension",
187187
"querying custom granularities (with preaggregation) ECommerce: totalQuantity by half_year + dimension",
188-
"querying custom granularities ECommerce: count by two_mo_by_feb + no dimension + rollingCountByUnbounded",
189-
"querying custom granularities ECommerce: count by two_mo_by_feb + no dimension + rollingCountByTrailing",
190-
"querying custom granularities ECommerce: count by two_mo_by_feb + no dimension + rollingCountByLeading",
191188
"pre-aggregations Customers: running total without time dimension",
192189
"querying BigECommerce: totalProfitYearAgo",
193190
"SQL API: post-aggregate percentage of total",

packages/cubejs-testing-drivers/fixtures/bigquery.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
"querying BigECommerce: rolling window by 2 day without date range",
164164
"querying BigECommerce: rolling window by 2 month without date range",
165165
"querying BigECommerce: rolling window YTD without date range",
166+
"querying custom granularities ECommerce: count by two_mo_by_feb + no dimension + rollingCountByLeading without date range",
166167

167168
"---------------------------------------",
168169
"SKIPPED SQL API (Need work)",
@@ -188,6 +189,7 @@
188189
"querying ECommerce: total quantity, avg discount, total sales, total profit by product + order + total -- rounding in athena",
189190
"querying ECommerce: total sales, total profit by month + order (date) + total -- doesn't work with the BigQuery",
190191
"querying ECommerce: total quantity, avg discount, total sales, total profit by product + order + total -- noisy test",
192+
"querying custom granularities ECommerce: count by two_mo_by_feb + no dimension + rollingCountByLeading without date range",
191193
"querying BigECommerce: null sum",
192194
"querying BigECommerce: null boolean",
193195
"querying BigECommerce: rolling window by 2 day without date range",

packages/cubejs-testing-drivers/fixtures/clickhouse.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@
200200
"querying BigECommerce: rolling window by 2 day without date range",
201201
"querying BigECommerce: rolling window by 2 month without date range",
202202
"querying BigECommerce: rolling window YTD without date range",
203+
"querying custom granularities ECommerce: count by two_mo_by_feb + no dimension + rollingCountByLeading without date range",
203204

204205
"---------------------------------------",
205206
"Custom Granularities ",

packages/cubejs-testing-drivers/fixtures/databricks-jdbc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@
216216
"querying BigECommerce: rolling window by 2 day without date range",
217217
"querying BigECommerce: rolling window by 2 month without date range",
218218
"querying BigECommerce: rolling window YTD without date range",
219+
"querying custom granularities ECommerce: count by two_mo_by_feb + no dimension + rollingCountByLeading without date range",
219220

220221
"---------------------------------------",
221222
"Custom Granularities ",

packages/cubejs-testing-drivers/fixtures/mssql.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
"querying BigECommerce: rolling window by 2 day without date range",
143143
"querying BigECommerce: rolling window by 2 month without date range",
144144
"querying BigECommerce: rolling window YTD without date range",
145+
"querying custom granularities ECommerce: count by two_mo_by_feb + no dimension + rollingCountByLeading without date range",
145146

146147
"---------------------------------------",
147148
"SKIPPED SQL API (Need work)",

0 commit comments

Comments
 (0)