Skip to content

Commit b238a29

Browse files
authored
feat(tesseract): Support time series queries in Databricks (#9871)
* feat(tesseract): Support time series queries in Databricks * run databricks drivers-tests with tesseract * fix templates.statements.generated_time_series_select * fix templates.statements.generated_time_series_with_cte_range_source * enable supportGeneratedSeriesForCustomTd * add snapshot: querying BigECommerce: rolling window by 2 day without date range * add snapshot: querying BigECommerce: rolling window by 2 month without date range * update snapshot: querying BigECommerce: rolling window YTD without date range * add snapshot: querying BigECommerce with Retail Calendar * add snapshot: querying custom granularities ECommerce: count by two_mo_by_feb + no dimension + rollingCountByLeading without date range * add snapshot: SQL API: Extended nested Rollup over asterisk
1 parent 8208419 commit b238a29

File tree

4 files changed

+744
-44
lines changed

4 files changed

+744
-44
lines changed

.github/workflows/drivers-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ jobs:
273273
use_tesseract_sql_planner: true
274274
- database: athena-export-bucket-s3
275275
use_tesseract_sql_planner: true
276+
- database: databricks-jdbc
277+
use_tesseract_sql_planner: true
276278
fail-fast: false
277279

278280
steps:

packages/cubejs-databricks-jdbc-driver/src/DatabricksQuery.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ export class DatabricksQuery extends BaseQuery {
161161
return 120;
162162
}
163163

164+
public supportGeneratedSeriesForCustomTd() {
165+
return true;
166+
}
167+
164168
public sqlTemplates() {
165169
const templates = super.sqlTemplates();
166170
templates.functions.CURRENTDATE = 'CURRENT_DATE';
@@ -178,6 +182,32 @@ export class DatabricksQuery extends BaseQuery {
178182
templates.expressions.interval_single_date_part = 'INTERVAL \'{{ num }}\' {{ date_part }}';
179183
templates.quotes.identifiers = '`';
180184
templates.quotes.escape = '``';
185+
templates.statements.time_series_select = 'SELECT date_from::timestamp AS `date_from`,\n' +
186+
'date_to::timestamp AS `date_to` \n' +
187+
'FROM(\n' +
188+
' VALUES ' +
189+
'{% for time_item in seria %}' +
190+
'(\'{{ time_item | join(\'\\\', \\\'\') }}\')' +
191+
'{% if not loop.last %}, {% endif %}' +
192+
'{% endfor %}' +
193+
') AS dates (date_from, date_to)';
194+
templates.statements.generated_time_series_select = 'SELECT d AS date_from,\n' +
195+
'(d + INTERVAL {{ granularity }}) - INTERVAL 1 MILLISECOND AS date_to\n' +
196+
' FROM (SELECT explode(sequence(\n' +
197+
' from_utc_timestamp({{ start }}, \'UTC\'), from_utc_timestamp({{ end }}, \'UTC\'), INTERVAL {{ granularity }}\n' +
198+
' )) AS d)';
199+
templates.statements.generated_time_series_with_cte_range_source =
200+
'SELECT d AS date_from,\n' +
201+
'(d + INTERVAL {{ granularity }}) - INTERVAL 1 MILLISECOND AS date_to\n' +
202+
'FROM {{ range_source }}\n' +
203+
'LATERAL VIEW explode(\n' +
204+
' sequence(\n' +
205+
' CAST({{ min_name }} AS TIMESTAMP),\n' +
206+
' CAST({{ max_name }} AS TIMESTAMP),\n' +
207+
' INTERVAL {{ granularity }}\n' +
208+
' )\n' +
209+
') dates AS d';
210+
181211
// TODO: Databricks has `TIMESTAMP_NTZ` with logic similar to Pg's `TIMESTAMP`
182212
// but that requires Runtime 13.3+. Should this be enabled?
183213
// templates.types.timestamp = 'TIMESTAMP_NTZ';

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,5 +235,48 @@
235235
"SQL API: Nested Rollup with aliases",
236236
"SQL API: Nested Rollup over asteriks",
237237
"SQL API: Extended nested Rollup over asterisk"
238+
],
239+
"tesseractSkip": [
240+
"must download query from the data source via memory",
241+
"must download query from the data source via stream",
242+
"for the Customers.RollingExternal",
243+
"for the Customers.RollingInternal",
244+
"for the ECommerce.SimpleAnalysisExternal",
245+
"for the ECommerce.SimpleAnalysisInternal",
246+
"for the ECommerce.TimeAnalysisInternal",
247+
"for the ECommerce.TimeAnalysisExternal",
248+
"querying Products: dimensions -- doesn't work wo ordering",
249+
"querying ECommerce: total quantity, avg discount, total sales, total profit by product + order + total -- rounding in athena",
250+
"querying ECommerce: total sales, total profit by month + order (date) + total -- doesn't work with the BigQuery",
251+
"querying ECommerce: total quantity, avg discount, total sales, total profit by product + order + total -- noisy test",
252+
"querying custom granularities ECommerce: count by three_months_by_march + no dimension",
253+
"querying custom granularities ECommerce: count by three_months_by_march + dimension",
254+
"SQL API: SQL push down push to cube quoted alias",
255+
"SQL API: Complex Rollup",
256+
"SQL API: Simple Rollup",
257+
"SQL API: Rollup over exprs",
258+
"SQL API: Rollup with aliases",
259+
"SQL API: Nested Rollup",
260+
"SQL API: Nested Rollup with aliases",
261+
"SQL API: Nested Rollup over asterisk",
262+
"SQL API: Rolling Window YTD (year + month + day + date_trunc equal)",
263+
"SQL API: Rolling Window YTD (year + month + day + date_trunc IN)",
264+
265+
"---- Different results comparing to baseQuery version. Need to investigate ----",
266+
"querying ECommerce: dimensions",
267+
"querying ECommerce: dimensions + order",
268+
"querying ECommerce: dimensions + limit",
269+
"querying ECommerce: dimensions + total",
270+
"querying ECommerce: dimensions + order + limit + total",
271+
"querying ECommerce: dimensions + order + total + offset",
272+
"querying ECommerce: dimensions + order + limit + total + offset",
273+
"filtering ECommerce: contains dimensions, first",
274+
"filtering ECommerce: contains dimensions, second",
275+
"filtering ECommerce: startsWith + dimensions, first",
276+
"filtering ECommerce: startsWith + dimensions, second",
277+
"filtering ECommerce: endsWith + dimensions, first",
278+
"filtering ECommerce: endsWith + dimensions, second",
279+
"querying BigECommerce: rolling window YTD (month + week)",
280+
"querying BigECommerce: rolling window YTD (month + week + no gran)"
238281
]
239282
}

0 commit comments

Comments
 (0)