Skip to content

Commit 32d50a5

Browse files
authored
fix(schema-compiler): Fix datetime tz conversion for Athena/Trino (#10207)
1 parent 6f4a650 commit 32d50a5

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { PrestodbQuery } from './PrestodbQuery';
2+
3+
export class AthenaQuery extends PrestodbQuery {
4+
// Athena doesn't require odd prestodb manual datetime offset calculations
5+
// as it uses mature timestamps models
6+
public override convertTz(field) {
7+
return this.timezone ? `CAST((${field} AT TIME ZONE '${this.timezone}') AS TIMESTAMP)` : field;
8+
}
9+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class PrestodbQuery extends BaseQuery {
4949
return `from_iso8601_timestamp(${value})`;
5050
}
5151

52-
public convertTz(field) {
52+
public override convertTz(field) {
5353
const atTimezone = `${field} AT TIME ZONE '${this.timezone}'`;
5454
return this.timezone ?
5555
`CAST(date_add('minute', timezone_minute(${atTimezone}), date_add('hour', timezone_hour(${atTimezone}), ${field})) AS TIMESTAMP)` :

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { SqliteQuery } from './SqliteQuery';
1515
import { AWSElasticSearchQuery } from './AWSElasticSearchQuery';
1616
import { ElasticSearchQuery } from './ElasticSearchQuery';
1717
import { CubeStoreQuery } from './CubeStoreQuery';
18+
import { AthenaQuery } from './AthenaQuery';
19+
import { TrinoQuery } from './TrinoQuery';
1820

1921
const ADAPTERS = {
2022
postgres: PostgresQuery,
@@ -26,7 +28,8 @@ const ADAPTERS = {
2628
bigquery: BigqueryQuery,
2729
prestodb: PrestodbQuery,
2830
qubole_prestodb: PrestodbQuery,
29-
athena: PrestodbQuery,
31+
athena: AthenaQuery,
32+
trino: TrinoQuery,
3033
vertica: VerticaQuery,
3134
snowflake: SnowflakeQuery,
3235
clickhouse: ClickHouseQuery,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { PrestodbQuery } from './PrestodbQuery';
2+
3+
export class TrinoQuery extends PrestodbQuery {
4+
// Trino doesn't require odd prestodb manual datetime offset calculations
5+
// as it uses mature timestamps models
6+
public override convertTz(field) {
7+
return this.timezone ? `CAST((${field} AT TIME ZONE '${this.timezone}') AS TIMESTAMP)` : field;
8+
}
9+
}

0 commit comments

Comments
 (0)