Skip to content

Commit

Permalink
fix(presto-driver): optimize testConnection() to issue get nodes() in…
Browse files Browse the repository at this point in the history
…stead of heavy show catalogs
  • Loading branch information
KSDaemon committed Jan 17, 2025
1 parent 6d75c60 commit 3b02131
Showing 1 changed file with 13 additions and 10 deletions.
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

0 comments on commit 3b02131

Please sign in to comment.