@@ -20,6 +20,7 @@ import { JDBCDriver, JDBCDriverConfiguration, } from '@cubejs-backend/jdbc-drive
2020import { DatabricksQuery } from './DatabricksQuery' ;
2121import {
2222 extractAndRemoveUidPwdFromJdbcUrl ,
23+ parseDatabricksJdbcUrl ,
2324 resolveJDBCDriver
2425} from './helpers' ;
2526
@@ -124,6 +125,11 @@ type ColumnInfo = {
124125 type : GenericDataBaseType ;
125126} ;
126127
128+ export type ParsedConnectionProperties = {
129+ host : string ,
130+ warehouseId : string ,
131+ } ;
132+
127133const DatabricksToGenericType : Record < string , string > = {
128134 binary : 'hll_datasketches' ,
129135 'decimal(10,0)' : 'bigint' ,
@@ -143,6 +149,8 @@ export class DatabricksDriver extends JDBCDriver {
143149 */
144150 protected readonly config : DatabricksDriverConfiguration ;
145151
152+ private readonly parsedConnectionProperties : ParsedConnectionProperties ;
153+
146154 public static dialectClass ( ) {
147155 return DatabricksQuery ;
148156 }
@@ -262,38 +270,46 @@ export class DatabricksDriver extends JDBCDriver {
262270
263271 super ( config ) ;
264272 this . config = config ;
273+ this . parsedConnectionProperties = parseDatabricksJdbcUrl ( url ) ;
265274 this . showSparkProtocolWarn = showSparkProtocolWarn ;
266275 }
267276
268- /**
269- * @override
270- */
271- public readOnly ( ) {
277+ public override readOnly ( ) {
272278 return ! ! this . config . readOnly ;
273279 }
274280
275- /**
276- * @override
277- */
278- public capabilities ( ) : DriverCapabilities {
281+ public override capabilities ( ) : DriverCapabilities {
279282 return {
280283 unloadWithoutTempTable : true ,
281284 incrementalSchemaLoading : true
282285 } ;
283286 }
284287
285- /**
286- * @override
287- */
288- public setLogger ( logger : any ) {
288+ public override setLogger ( logger : any ) {
289289 super . setLogger ( logger ) ;
290290 this . showDeprecations ( ) ;
291291 }
292292
293- /**
294- * @override
295- */
296- public async loadPreAggregationIntoTable (
293+ public override async testConnection ( ) {
294+ const token = `Bearer ${ this . config . properties . PWD } ` ;
295+
296+ const res = await fetch ( `https://${ this . parsedConnectionProperties . host } /api/2.0/sql/warehouses/${ this . parsedConnectionProperties . warehouseId } ` , {
297+ headers : { Authorization : token } ,
298+ } ) ;
299+
300+ if ( ! res . ok ) {
301+ throw new Error ( `Databricks API error: ${ res . statusText } ` ) ;
302+ }
303+
304+ const data = await res . json ( ) ;
305+
306+ // We don't need to check the actual status, because SQL WH will auto resume on real connection
307+ // if (data.state !== 'RUNNING') {
308+ // throw new Error(`Warehouse not running (current state: ${data.state})`);
309+ // }
310+ }
311+
312+ public override async loadPreAggregationIntoTable (
297313 preAggregationTableName : string ,
298314 loadSql : string ,
299315 params : unknown [ ] ,
@@ -320,10 +336,7 @@ export class DatabricksDriver extends JDBCDriver {
320336 }
321337 }
322338
323- /**
324- * @override
325- */
326- public async query < R = unknown > (
339+ public override async query < R = unknown > (
327340 query : string ,
328341 values : unknown [ ] ,
329342 ) : Promise < R [ ] > {
@@ -357,10 +370,7 @@ export class DatabricksDriver extends JDBCDriver {
357370 }
358371 }
359372
360- /**
361- * @override
362- */
363- public dropTable ( tableName : string , options ?: QueryOptions ) : Promise < unknown > {
373+ public override dropTable ( tableName : string , options ?: QueryOptions ) : Promise < unknown > {
364374 const tableFullName = `${
365375 this . config ?. catalog ? `${ this . config . catalog } .` : ''
366376 } ${ tableName } `;
@@ -392,10 +402,7 @@ export class DatabricksDriver extends JDBCDriver {
392402 }
393403 }
394404
395- /**
396- * @override
397- */
398- protected async getCustomClassPath ( ) {
405+ protected override async getCustomClassPath ( ) {
399406 return resolveJDBCDriver ( ) ;
400407 }
401408
0 commit comments