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
2 changes: 2 additions & 0 deletions .github/workflows/drivers-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ jobs:
use_tesseract_sql_planner: true
- database: bigquery-export-bucket-gcs
use_tesseract_sql_planner: true
- database: athena-export-bucket-s3
use_tesseract_sql_planner: true
fail-fast: false

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust-cubesql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ jobs:
matrix:
# We do not need to test under all versions, we do it under linux
node-version: [22.x]
os-version: [windows-2019]
os-version: [windows-2022]
python-version: ["fallback"]
fail-fast: false

Expand Down
15 changes: 13 additions & 2 deletions packages/cubejs-schema-compiler/src/adapter/BaseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,8 @@ export class BaseQuery {
* @returns {string}
*/
subtractInterval(date, interval) {
return `${date} - interval '${interval}'`;
const intervalStr = this.intervalString(interval);
return `${date} - interval ${intervalStr}`;
}

/**
Expand All @@ -1087,7 +1088,16 @@ export class BaseQuery {
* @returns {string}
*/
addInterval(date, interval) {
return `${date} + interval '${interval}'`;
const intervalStr = this.intervalString(interval);
return `${date} + interval ${intervalStr}`;
}

/**
* @param {string} interval
* @returns {string}
*/
intervalString(interval) {
return `'${interval}'`;
}

/**
Expand Down Expand Up @@ -4111,6 +4121,7 @@ export class BaseQuery {
},
tesseract: {
ilike: '{{ expr }} {% if negated %}NOT {% endif %}ILIKE {{ pattern }}', // May require different overloads in Tesseract than the ilike from expressions used in SQLAPI.
series_bounds_cast: '{{ expr }}'
},
filters: {
equals: '{{ column }} = {{ value }}{{ is_null_check }}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ export class BigqueryQuery extends BaseQuery {
return this.subtractInterval(timestamp, interval);
}

public intervalString(interval: string): string {
return `${interval}`;
}

public addTimestampInterval(timestamp, interval) {
return this.addInterval(timestamp, interval);
}
Expand Down Expand Up @@ -353,6 +357,7 @@ export class BigqueryQuery extends BaseQuery {
delete templates.expressions.like_escape;
templates.filters.like_pattern = 'CONCAT({% if start_wild %}\'%\'{% else %}\'\'{% endif %}, LOWER({{ value }}), {% if end_wild %}\'%\'{% else %}\'\'{% endif %})';
templates.tesseract.ilike = 'LOWER({{ expr }}) {% if negated %}NOT {% endif %} LIKE {{ pattern }}';
templates.tesseract.series_bounds_cast = 'TIMESTAMP({{ expr }})';
templates.types.boolean = 'BOOL';
templates.types.float = 'FLOAT64';
templates.types.double = 'FLOAT64';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ export class PostgresQuery extends BaseQuery {
templates.types.binary = 'BYTEA';
templates.operators.is_not_distinct_from = 'IS NOT DISTINCT FROM';
templates.statements.generated_time_series_select = 'SELECT d AS "date_from",\n' +
'd + interval \'{{ granularity }}\' - interval \'1 millisecond\' AS "date_to" \n' +
'FROM generate_series({{ start }}::timestamp, {{ end }}:: timestamp, \'{{ granularity }}\'::interval) d ';
'd + interval {{ granularity }} - interval \'1 millisecond\' AS "date_to" \n' +
'FROM generate_series({{ start }}::timestamp, {{ end }}:: timestamp, {{ granularity }}::interval) d ';
templates.statements.generated_time_series_with_cte_range_source = 'SELECT d AS "date_from",\n' +
'd + interval \'{{ granularity }}\' - interval \'1 millisecond\' AS "date_to" \n' +
'FROM {{ range_source }}, LATERAL generate_series({{ range_source }}.{{ min_name }}, {{ range_source }}.{{ max_name }}, \'{{ granularity }}\'::interval) d ';
'd + interval {{ granularity }} - interval \'1 millisecond\' AS "date_to" \n' +
'FROM {{ range_source }}, LATERAL generate_series({{ range_source }}.{{ min_name }}, {{ range_source }}.{{ max_name }}, {{ granularity }}::interval) d ';
return templates;
}

Expand Down
39 changes: 30 additions & 9 deletions packages/cubejs-schema-compiler/src/adapter/PrestodbQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,9 @@ export class PrestodbQuery extends BaseQuery {
return `date_trunc('${GRANULARITY_TO_INTERVAL[granularity]}', ${dimension})`;
}

public subtractInterval(date, interval) {
public intervalString(interval: string): string {
const [intervalValue, intervalUnit] = interval.split(' ');
return `${date} - interval '${intervalValue}' ${intervalUnit}`;
}

public addInterval(date, interval) {
const [intervalValue, intervalUnit] = interval.split(' ');
return `${date} + interval '${intervalValue}' ${intervalUnit}`;
return `'${intervalValue}' ${intervalUnit}`;
}

public seriesSql(timeDimension) {
Expand Down Expand Up @@ -138,9 +133,16 @@ export class PrestodbQuery extends BaseQuery {
templates.functions.DATETRUNC = 'DATE_TRUNC({{ args_concat }})';
templates.functions.DATEPART = 'DATE_PART({{ args_concat }})';
delete templates.functions.PERCENTILECONT;
templates.statements.select = 'SELECT {{ select_concat | map(attribute=\'aliased\') | join(\', \') }} \n' +
'FROM (\n {{ from }}\n) AS {{ from_alias }} \n' +
templates.statements.select = '{% if ctes %} WITH \n' +
'{{ ctes | join(\',\n\') }}\n' +
'{% endif %}' +
'SELECT {{ select_concat | map(attribute=\'aliased\') | join(\', \') }} {% if from %}\n' +
'FROM (\n {{ from }}\n) AS {{ from_alias }} {% elif from_prepared %}\n' +
'FROM {{ from_prepared }}' +
'{% endif %}' +
'{% if filter %}\nWHERE {{ filter }}{% endif %}' +
'{% if group_by %} GROUP BY {{ group_by }}{% endif %}' +
'{% if having %}\nHAVING {{ having }}{% endif %}' +
'{% if order_by %} ORDER BY {{ order_by | map(attribute=\'expr\') | join(\', \') }}{% endif %}' +
'{% if offset is not none %}\nOFFSET {{ offset }}{% endif %}' +
'{% if limit is not none %}\nLIMIT {{ limit }}{% endif %}';
Expand All @@ -153,6 +155,25 @@ export class PrestodbQuery extends BaseQuery {
// Presto intervals have a YearMonth or DayTime type variants, but no universal type
delete templates.types.interval;
templates.types.binary = 'VARBINARY';
templates.tesseract.ilike = 'LOWER({{ expr }}) {% if negated %}NOT {% endif %} LIKE {{ pattern }}';
templates.filters.like_pattern = 'CONCAT({% if start_wild %}\'%\'{% else %}\'\'{% endif %}, LOWER({{ value }}), {% if end_wild %}\'%\'{% else %}\'\'{% endif %}) ESCAPE \'\\\'';
templates.statements.time_series_select = 'SELECT from_iso8601_timestamp(dates.f) date_from, from_iso8601_timestamp(dates.t) date_to \n' +
'FROM (\n' +
'{% for time_item in seria %}' +
' select \'{{ time_item[0] }}\' f, \'{{ time_item[1] }}\' t \n' +
'{% if not loop.last %} UNION ALL\n{% endif %}' +
'{% endfor %}' +
') AS dates';
templates.statements.generated_time_series_select = 'SELECT d AS date_from,\n' +
'date_add(\'MILLISECOND\', -1, d + interval {{ granularity }}) AS date_to\n' +
'FROM UNNEST(\n' +
'SEQUENCE(CAST(from_iso8601_timestamp({{ start }}) AS TIMESTAMP), CAST(from_iso8601_timestamp({{ end }}) AS TIMESTAMP), INTERVAL {{ granularity }})\n' +
') AS dates(d)';
templates.statements.generated_time_series_with_cte_range_source = 'SELECT d AS date_from,\n' +
'date_add(\'MILLISECOND\', -1, d + interval {{ granularity }}) AS date_to\n' +
'FROM {{ range_source }} CROSS JOIN UNNEST(\n' +
'SEQUENCE(CAST({{ range_source }}.{{ min_name }} AS TIMESTAMP), CAST({{ range_source }}.{{ max_name }} AS TIMESTAMP), INTERVAL {{ granularity }})\n' +
') AS dates(d)';
return templates;
}

Expand Down
36 changes: 36 additions & 0 deletions packages/cubejs-testing-drivers/fixtures/athena.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,41 @@
"SQL API: Nested Rollup with aliases",
"SQL API: Nested Rollup over asterisk",
"SQL API: Extended nested Rollup over asterisk"
],
"tesseractSkip": [
"for the ECommerce.TimeAnalysisExternal",
"for the ECommerce.TimeAnalysisInternal",

"querying Products: dimensions -- doesn't work wo ordering",
"querying ECommerce: total quantity, avg discount, total sales, total profit by product + order + total -- rounding in athena",
"querying ECommerce: total sales, total profit by month + order (date) + total -- doesn't work with the BigQuery",
"querying ECommerce: total quantity, avg discount, total sales, total profit by product + order + total -- noisy test",
"querying BigECommerce: partitioned pre-agg",
"querying BigECommerce: null sum",
"querying BigECommerce: null boolean",
"--------------------",


"querying BigECommerce: rolling window by 2 week",
"querying custom granularities ECommerce: count by three_months_by_march + no dimension",
"querying custom granularities ECommerce: count by three_months_by_march + dimension",
"querying custom granularities (with preaggregation) ECommerce: totalQuantity by half_year + no dimension",
"querying custom granularities (with preaggregation) ECommerce: totalQuantity by half_year + dimension",
"querying custom granularities ECommerce: count by two_mo_by_feb + no dimension + rollingCountByUnbounded",
"querying custom granularities ECommerce: count by two_mo_by_feb + no dimension + rollingCountByTrailing",
"querying custom granularities ECommerce: count by two_mo_by_feb + no dimension + rollingCountByLeading",
"pre-aggregations Customers: running total without time dimension",
"querying BigECommerce: totalProfitYearAgo",
"SQL API: post-aggregate percentage of total",
"SQL API: Simple Rollup",
"SQL API: Complex Rollup",
"SQL API: Nested Rollup",
"SQL API: Rollup with aliases",
"SQL API: Rollup over exprs",
"SQL API: Nested Rollup with aliases",
"SQL API: Nested Rollup over asterisk",
"SQL API: Extended nested Rollup over asterisk",
"SQL API: Timeshift measure from cube",
"SQL API: SQL push down push to cube quoted alias"
]
}
Loading
Loading