From 3b021310b517119d52eac8c7700f4c64a95e918e Mon Sep 17 00:00:00 2001 From: Konstantin Burkalev Date: Fri, 17 Jan 2025 16:28:58 +0200 Subject: [PATCH] fix(presto-driver): optimize testConnection() to issue get nodes() instead of heavy show catalogs --- .../src/PrestoDriver.ts | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/cubejs-prestodb-driver/src/PrestoDriver.ts b/packages/cubejs-prestodb-driver/src/PrestoDriver.ts index 8232349ddbd3e..8822acd5f3ef8 100644 --- a/packages/cubejs-prestodb-driver/src/PrestoDriver.ts +++ b/packages/cubejs-prestodb-driver/src/PrestoDriver.ts @@ -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 (> this.queryPromised(query, false)) - .then(catalogs => { - if (catalogs.length === 0) { - throw new Error(`Catalog not found '${this.catalog}'`); + public async testConnection(): Promise { + 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 { @@ -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 @@ -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 { @@ -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;