Skip to content

Commit c54579f

Browse files
committed
ConvertTZ and date_trunc should not change the data type as time dims should be timestamps
1 parent 59210da commit c54579f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class BigqueryQuery extends BaseQuery {
4242
}
4343

4444
public convertTz(field) {
45-
return `DATETIME(${this.timeStampCast(field)}, '${this.timezone}')`;
45+
return `TIMESTAMP(DATETIME(${field}), '${this.timezone}')`;
4646
}
4747

4848
public timeStampCast(value) {
@@ -58,7 +58,7 @@ export class BigqueryQuery extends BaseQuery {
5858
}
5959

6060
public timeGroupedColumn(granularity, dimension) {
61-
return `DATETIME_TRUNC(${dimension}, ${GRANULARITY_TO_INTERVAL[granularity]})`;
61+
return this.timeStampCast(`DATETIME_TRUNC(${dimension}, ${GRANULARITY_TO_INTERVAL[granularity]})`);
6262
}
6363

6464
/**
@@ -72,7 +72,7 @@ export class BigqueryQuery extends BaseQuery {
7272

7373
return `(${this.dateTimeCast(`'${origin}'`)} + INTERVAL ${intervalFormatted} *
7474
CAST(FLOOR(
75-
DATETIME_DIFF(${source}, ${this.dateTimeCast(`'${origin}'`)}, ${timeUnit}) /
75+
DATETIME_DIFF(${this.dateTimeCast(source)}, ${this.dateTimeCast(`'${origin}'`)}, ${timeUnit}) /
7676
DATETIME_DIFF(${beginOfTime} + INTERVAL ${intervalFormatted}, ${beginOfTime}, ${timeUnit})
7777
) AS INT64))`;
7878
}

0 commit comments

Comments
 (0)