Skip to content

feat(trino-driver): Add special testConnection for Trino #9634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cubejs-prestodb-driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"dependencies": {
"@cubejs-backend/base-driver": "1.3.19",
"@cubejs-backend/shared": "1.3.19",
"presto-client": "^0.12.2",
"presto-client": "^1.1.0",
"ramda": "^0.27.0",
"sqlstring": "^2.3.1"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/cubejs-prestodb-driver/src/PrestoDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ export class PrestoDriver extends BaseDriver implements DriverInterface {
return 2;
}

private config: PrestoDriverConfiguration;
protected readonly config: PrestoDriverConfiguration;

private catalog: string | undefined;
protected readonly catalog: string | undefined;

private client: any;
protected client: any;

/**
* Class constructor.
Expand Down
2 changes: 1 addition & 1 deletion packages/cubejs-schema-compiler/src/adapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export * from './CubeStoreQuery';
export * from './MysqlQuery';
export * from './PostgresQuery';
export * from './MssqlQuery';
export * from './PrestodbQuery';

// Candidates to move from this package to drivers packages
// export * from './PrestodbQuery';
// export * from './RedshiftQuery';
// export * from './SnowflakeQuery';
// export * from './SqliteQuery';
Expand Down
3 changes: 2 additions & 1 deletion packages/cubejs-trino-driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"@cubejs-backend/prestodb-driver": "1.3.19",
"@cubejs-backend/schema-compiler": "1.3.19",
"@cubejs-backend/shared": "1.3.19",
"presto-client": "^0.12.2",
"node-fetch": "^2.6.1",
"presto-client": "^1.1.0",
"sqlstring": "^2.3.1"
},
"license": "Apache-2.0",
Expand Down
23 changes: 22 additions & 1 deletion packages/cubejs-trino-driver/src/TrinoDriver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fetch from 'node-fetch';
import { PrestoDriver } from '@cubejs-backend/prestodb-driver';
import { PrestodbQuery } from '@cubejs-backend/schema-compiler/dist/src/adapter/PrestodbQuery';
import { PrestodbQuery } from '@cubejs-backend/schema-compiler';

export class TrinoDriver extends PrestoDriver {
public constructor(options: any) {
Expand All @@ -9,4 +10,24 @@ export class TrinoDriver extends PrestoDriver {
public static dialectClass() {
return PrestodbQuery;
}

public override async testConnection(): Promise<void> {
const { host, port, ssl, basic_auth: basicAuth } = this.config;
const protocol = ssl ? 'https' : 'http';
const url = `${protocol}://${host}:${port}/v1/info`;
const headers: Record<string, string> = {};

if (basicAuth) {
const { user, password } = basicAuth;
const encoded = Buffer.from(`${user}:${password}`).toString('base64');
headers.Authorization = `Basic ${encoded}`;
}

const response = await fetch(url, { method: 'GET', headers });

if (!response.ok) {
const text = await response.text();
throw new Error(`Connection test failed: ${response.status} ${response.statusText} - ${text}`);
}
}
}
12 changes: 7 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14373,7 +14373,7 @@ focus-lock@^1.3.5:
dependencies:
tslib "^2.0.3"

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

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

prettier@^1.16.4:
version "1.19.1"
Expand Down
Loading