Skip to content

Commit d39e4a2

Browse files
authored
fix(clickhouse-driver): Correct parsing for DateTime('timezone') (#7565)
1 parent fe10c9b commit d39e4a2

File tree

9 files changed

+63
-13
lines changed

9 files changed

+63
-13
lines changed

.github/workflows/drivers-tests.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ on:
77
paths:
88
- '.github/workflows/drivers-tests.yml'
99

10+
- 'packages/cubejs-testing-drivers/**'
11+
- 'packages/cubejs-testing-shared/**'
1012
- 'packages/cubejs-query-orchestrator/src/**'
1113
- 'packages/cubejs-base-driver/src/**'
1214
- 'packages/cubejs-jdbc-driver/src/**'
@@ -22,6 +24,8 @@ on:
2224
paths:
2325
- '.github/workflows/drivers-tests.yml'
2426

27+
- 'packages/cubejs-testing-drivers/**'
28+
- 'packages/cubejs-testing-shared/**'
2529
- 'packages/cubejs-query-orchestrator/src/**'
2630
- 'packages/cubejs-base-driver/src/**'
2731
- 'packages/cubejs-jdbc-driver/src/**'
@@ -69,7 +73,7 @@ jobs:
6973

7074
# Building docker
7175
- name: Login to DockerHub
72-
uses: docker/login-action@v1
76+
uses: docker/login-action@v3
7377
with:
7478
username: ${{ secrets.DOCKERHUB_USERNAME }}
7579
password: ${{ secrets.DOCKERHUB_TOKEN }}

.github/workflows/master.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
- name: Check out the repo
4747
uses: actions/checkout@v4
4848
- name: Login to DockerHub
49-
uses: docker/login-action@v1
49+
uses: docker/login-action@v3
5050
with:
5151
username: ${{ secrets.DOCKERHUB_USERNAME }}
5252
password: ${{ secrets.DOCKERHUB_TOKEN }}

.github/workflows/publish.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ jobs:
404404
echo ::set-output name=tags::${TAGS}
405405
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
406406
- name: Login to DockerHub
407-
uses: docker/login-action@v1
407+
uses: docker/login-action@v3
408408
with:
409409
username: ${{ secrets.DOCKERHUB_USERNAME }}
410410
password: ${{ secrets.DOCKERHUB_TOKEN }}
@@ -480,7 +480,7 @@ jobs:
480480
echo ::set-output name=tags::${TAGS}
481481
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
482482
- name: Login to DockerHub
483-
uses: docker/login-action@v1
483+
uses: docker/login-action@v3
484484
with:
485485
username: ${{ secrets.DOCKERHUB_USERNAME }}
486486
password: ${{ secrets.DOCKERHUB_TOKEN }}
@@ -552,7 +552,7 @@ jobs:
552552
echo ::set-output name=tags::${TAGS}
553553
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
554554
- name: Login to DockerHub
555-
uses: docker/login-action@v1
555+
uses: docker/login-action@v3
556556
with:
557557
username: ${{ secrets.DOCKERHUB_USERNAME }}
558558
password: ${{ secrets.DOCKERHUB_TOKEN }}
@@ -648,7 +648,7 @@ jobs:
648648
echo ::set-output name=tags::${TAGS}
649649
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
650650
- name: Login to DockerHub
651-
uses: docker/login-action@v1
651+
uses: docker/login-action@v3
652652
with:
653653
username: ${{ secrets.DOCKERHUB_USERNAME }}
654654
password: ${{ secrets.DOCKERHUB_TOKEN }}

.github/workflows/push-cross-images.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
uses: actions/checkout@v4
3030
- name: Login to DockerHub
3131
if: ${{ github.ref == 'refs/heads/master' }}
32-
uses: docker/login-action@v1
32+
uses: docker/login-action@v3
3333
with:
3434
username: ${{ secrets.DOCKERHUB_USERNAME }}
3535
password: ${{ secrets.DOCKERHUB_TOKEN }}

.github/workflows/rust-cubestore-master.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ jobs:
142142
echo ::set-output name=tags::${TAGS}
143143
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
144144
- name: Login to DockerHub
145-
uses: docker/login-action@v1
145+
uses: docker/login-action@v3
146146
with:
147147
username: ${{ secrets.DOCKERHUB_USERNAME }}
148148
password: ${{ secrets.DOCKERHUB_TOKEN }}

packages/cubejs-clickhouse-driver/src/HydrationStream.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ export function transformRow(row: Record<string, any>, meta: any) {
99
for (const [fieldName, value] of Object.entries(row)) {
1010
if (value !== null) {
1111
const metaForField = meta[fieldName];
12-
if (metaForField.type === 'DateTime') {
13-
row[fieldName] = `${value.substring(0, 10)}T${value.substring(11, 22)}.000`;
14-
} else if (metaForField.type.includes('DateTime64')) {
12+
if (metaForField.type.includes('DateTime64')) {
1513
row[fieldName] = moment.utc(value).format(moment.HTML5_FMT.DATETIME_LOCAL_MS);
14+
} else if (metaForField.type.includes('DateTime') /** Can be DateTime or DateTime('timezone') */) {
15+
row[fieldName] = `${value.substring(0, 10)}T${value.substring(11, 22)}.000`;
1616
} else if (metaForField.type.includes('Date')) {
1717
row[fieldName] = `${value}T00:00:00.000`;
1818
} else if (metaForField.type.includes('Int')

packages/cubejs-clickhouse-driver/test/ClickHouseDriver.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,40 @@ describe('ClickHouseDriver', () => {
239239
});
240240
});
241241

242+
it('datetime with specific timezone', async () => {
243+
await doWithDriver(async (driver) => {
244+
const rows = await driver.query('SELECT toDateTime(?, \'Asia/Istanbul\') as dt', [
245+
'2020-01-01 00:00:00'
246+
]);
247+
expect(rows).toEqual([{
248+
dt: '2020-01-01T00:00:00.000'
249+
}]);
250+
});
251+
});
252+
253+
it('query types_test', async () => {
254+
await doWithDriver(async (driver) => {
255+
const tableData = await driver.query('SELECT date, datetime, datetime64_micros FROM test.types_test ORDER BY int8', []);
256+
expect(tableData).toEqual([
257+
{
258+
date: '2020-01-01T00:00:00.000',
259+
datetime: '2020-01-01T00:00:00.000',
260+
datetime64_micros: '2020-01-01T00:00:00.000',
261+
},
262+
{
263+
date: '2020-01-02T00:00:00.000',
264+
datetime: '2020-01-02T00:00:00.000',
265+
datetime64_micros: '2020-01-02T00:00:00.123',
266+
},
267+
{
268+
date: '2020-01-03T00:00:00.000',
269+
datetime: '2020-01-03T00:00:00.000',
270+
datetime64_micros: '2020-01-03T00:00:00.234',
271+
}
272+
]);
273+
});
274+
});
275+
242276
it('stream', async () => {
243277
await doWithDriver(async (driver) => {
244278
const tableData = await driver.stream('SELECT * FROM test.types_test ORDER BY int8', [], {

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@
2222
"CLICKHOUSE_PASSWORD": "test",
2323
"CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT": 1
2424
},
25-
"ports" : ["8123"]
25+
"ports" : ["8123"],
26+
"healthcheck": {
27+
"test": "wget --spider -q --spider http://localhost:8123/ping || exit 1",
28+
"start_period": "5s",
29+
"interval": "10s",
30+
"retries": 3,
31+
"timeout": "5s"
32+
}
2633
},
2734
"cast": {
2835
"SELECT_PREFIX": "",

packages/cubejs-testing-drivers/src/helpers/runEnvironment.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as fs from 'fs-extra';
22
import * as path from 'path';
3-
import { ChildProcess, ChildProcessWithoutNullStreams, spawn } from 'child_process';
3+
import { ChildProcessWithoutNullStreams, spawn } from 'child_process';
44
import { config } from 'dotenv';
55
import yargs from 'yargs/yargs';
66
import { DockerComposeEnvironment, Wait } from 'testcontainers';
@@ -133,6 +133,11 @@ export async function runEnvironment(type: string, suf?: string): Promise<Enviro
133133
if (type === 'mssql') {
134134
compose.withWaitStrategy('data', Wait.forLogMessage('Service Broker manager has started'));
135135
}
136+
// TODO: Add health checks for all drivers
137+
if (type === 'clickhouse') {
138+
compose.withWaitStrategy('data', Wait.forHealthCheck());
139+
}
140+
136141
const environment = await compose.up();
137142

138143
const store = {

0 commit comments

Comments
 (0)