Skip to content

Commit 7f38e0c

Browse files
committed
feat(trino-driver): Add special testConnection for Trino
1 parent 89b00cf commit 7f38e0c

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@cubejs-backend/prestodb-driver": "1.3.18",
3030
"@cubejs-backend/schema-compiler": "1.3.18",
3131
"@cubejs-backend/shared": "1.3.18",
32+
"node-fetch": "^2.6.1",
3233
"presto-client": "^0.12.2",
3334
"sqlstring": "^2.3.1"
3435
},

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
}

0 commit comments

Comments
 (0)