Skip to content
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

fix(presto-driver): Optimize testConnection() to issue <get Nodes()> instead of heavy show catalogs query #9109

Merged
merged 1 commit into from
Jan 23, 2025
Merged
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
23 changes: 13 additions & 10 deletions packages/cubejs-prestodb-driver/src/PrestoDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,18 @@ export class PrestoDriver extends BaseDriver implements DriverInterface {
this.client = new presto.Client(this.config);
}

public testConnection() {
const query = SqlString.format('show catalogs like ?', [`%${this.catalog}%`]);

return (<Promise<any[]>> this.queryPromised(query, false))
.then(catalogs => {
if (catalogs.length === 0) {
throw new Error(`Catalog not found '${this.catalog}'`);
public async testConnection(): Promise<void> {
return new Promise((resolve, reject) => {
// Get node list of presto cluster and return it.
// @see https://prestodb.io/docs/current/rest/node.html
this.client.nodes(null, (error: any, _result: any[]) => {
if (error) {
reject(error);
} else {
resolve();
}
});
});
}

public query(query: string, values: unknown[]): Promise<any[]> {
Expand Down Expand Up @@ -230,7 +233,7 @@ export class PrestoDriver extends BaseDriver implements DriverInterface {
if (!this.config.exportBucket) {
throw new Error('Export bucket is not configured.');
}

if (!SUPPORTED_BUCKET_TYPES.includes(this.config.bucketType as string)) {
throw new Error(`Unsupported export bucket type: ${
this.config.bucketType
Expand All @@ -240,7 +243,7 @@ export class PrestoDriver extends BaseDriver implements DriverInterface {
const types = options.query
? await this.unloadWithSql(tableName, options.query.sql, options.query.params)
: await this.unloadWithTable(tableName);

const csvFile = await this.getCsvFiles(tableName);

return {
Expand Down Expand Up @@ -287,7 +290,7 @@ export class PrestoDriver extends BaseDriver implements DriverInterface {

const { bucketType, exportBucket } = this.config;
const types = await this.queryColumnTypes(params.typeSql, params.typeParams);

const { schema, tableName } = this.splitTableFullName(params.tableFullName);
const tableWithCatalogAndSchema = `${this.config.catalog}.${schema}.${tableName}`;
const protocol = bucketType === 'gcs' ? 'gs' : bucketType;
Expand Down
Loading