Skip to content

Commit ae10a76

Browse files
authored
feat(trino-driver): Add special testConnection for Trino (#9634)
* feat(trino-driver): Add special testConnection for Trino * update presto js client * lint fix
1 parent 577a09f commit ae10a76

File tree

6 files changed

+36
-12
lines changed

6 files changed

+36
-12
lines changed

packages/cubejs-prestodb-driver/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"dependencies": {
3030
"@cubejs-backend/base-driver": "1.3.19",
3131
"@cubejs-backend/shared": "1.3.19",
32-
"presto-client": "^0.12.2",
32+
"presto-client": "^1.1.0",
3333
"ramda": "^0.27.0",
3434
"sqlstring": "^2.3.1"
3535
},

packages/cubejs-prestodb-driver/src/PrestoDriver.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ export class PrestoDriver extends BaseDriver implements DriverInterface {
6060
return 2;
6161
}
6262

63-
private config: PrestoDriverConfiguration;
63+
protected readonly config: PrestoDriverConfiguration;
6464

65-
private catalog: string | undefined;
65+
protected readonly catalog: string | undefined;
6666

67-
private client: any;
67+
protected client: any;
6868

6969
/**
7070
* Class constructor.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ export * from './CubeStoreQuery';
1616
export * from './MysqlQuery';
1717
export * from './PostgresQuery';
1818
export * from './MssqlQuery';
19+
export * from './PrestodbQuery';
1920

2021
// Candidates to move from this package to drivers packages
21-
// export * from './PrestodbQuery';
2222
// export * from './RedshiftQuery';
2323
// export * from './SnowflakeQuery';
2424
// export * from './SqliteQuery';

packages/cubejs-trino-driver/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"@cubejs-backend/prestodb-driver": "1.3.19",
3030
"@cubejs-backend/schema-compiler": "1.3.19",
3131
"@cubejs-backend/shared": "1.3.19",
32-
"presto-client": "^0.12.2",
32+
"node-fetch": "^2.6.1",
33+
"presto-client": "^1.1.0",
3334
"sqlstring": "^2.3.1"
3435
},
3536
"license": "Apache-2.0",

packages/cubejs-trino-driver/src/TrinoDriver.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import fetch from 'node-fetch';
12
import { PrestoDriver } from '@cubejs-backend/prestodb-driver';
2-
import { PrestodbQuery } from '@cubejs-backend/schema-compiler/dist/src/adapter/PrestodbQuery';
3+
import { PrestodbQuery } from '@cubejs-backend/schema-compiler';
34

45
export class TrinoDriver extends PrestoDriver {
56
public constructor(options: any) {
@@ -9,4 +10,24 @@ export class TrinoDriver extends PrestoDriver {
910
public static dialectClass() {
1011
return PrestodbQuery;
1112
}
13+
14+
public override async testConnection(): Promise<void> {
15+
const { host, port, ssl, basic_auth: basicAuth } = this.config;
16+
const protocol = ssl ? 'https' : 'http';
17+
const url = `${protocol}://${host}:${port}/v1/info`;
18+
const headers: Record<string, string> = {};
19+
20+
if (basicAuth) {
21+
const { user, password } = basicAuth;
22+
const encoded = Buffer.from(`${user}:${password}`).toString('base64');
23+
headers.Authorization = `Basic ${encoded}`;
24+
}
25+
26+
const response = await fetch(url, { method: 'GET', headers });
27+
28+
if (!response.ok) {
29+
const text = await response.text();
30+
throw new Error(`Connection test failed: ${response.status} ${response.statusText} - ${text}`);
31+
}
32+
}
1233
}

yarn.lock

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14373,7 +14373,7 @@ focus-lock@^1.3.5:
1437314373
dependencies:
1437414374
tslib "^2.0.3"
1437514375

14376-
follow-redirects@^1.0.0, follow-redirects@^1.15.6:
14376+
follow-redirects@^1.0.0, follow-redirects@^1.15.3, follow-redirects@^1.15.6:
1437714377
version "1.15.9"
1437814378
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.9.tgz#a604fa10e443bf98ca94228d9eebcc2e8a2c8ee1"
1437914379
integrity sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==
@@ -21338,10 +21338,12 @@ prelude-ls@~1.1.2:
2133821338
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
2133921339
integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=
2134021340

21341-
presto-client@^0.12.2:
21342-
version "0.12.2"
21343-
resolved "https://registry.yarnpkg.com/presto-client/-/presto-client-0.12.2.tgz#9719064bed0bd98166ae4bf2ac2c08c0f6996544"
21344-
integrity sha512-rmoBoxM5mSQZ06SxwEHzMM8nn8W0XQJ2YmmxU9xMOM4r7Hs9Nec72VsM+M1FIYdteU9UIi40550weGs1uiTBNA==
21341+
presto-client@^1.1.0:
21342+
version "1.1.0"
21343+
resolved "https://registry.yarnpkg.com/presto-client/-/presto-client-1.1.0.tgz#cf0fe8a445db73c1e025256f5868fadaef4017a0"
21344+
integrity sha512-DOWEKp0eHP/x6Fupk5673vZND7OUxFtV9VUO9HMvf4DFzoWKTLMRAJ3o5/7Mgs5z9w5BEUKU88IZaume6LMelw==
21345+
dependencies:
21346+
follow-redirects "^1.15.3"
2134521347

2134621348
prettier@^1.16.4:
2134721349
version "1.19.1"

0 commit comments

Comments
 (0)