@@ -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,45 @@ 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+ if ( data . state !== 'RUNNING' ) {
307+ throw new Error ( `Warehouse not running (current state: ${ data . state } )` ) ;
308+ }
309+ }
310+
311+ public override async loadPreAggregationIntoTable (
297312 preAggregationTableName : string ,
298313 loadSql : string ,
299314 params : unknown [ ] ,
@@ -320,10 +335,7 @@ export class DatabricksDriver extends JDBCDriver {
320335 }
321336 }
322337
323- /**
324- * @override
325- */
326- public async query < R = unknown > (
338+ public override async query < R = unknown > (
327339 query : string ,
328340 values : unknown [ ] ,
329341 ) : Promise < R [ ] > {
@@ -357,10 +369,7 @@ export class DatabricksDriver extends JDBCDriver {
357369 }
358370 }
359371
360- /**
361- * @override
362- */
363- public dropTable ( tableName : string , options ?: QueryOptions ) : Promise < unknown > {
372+ public override dropTable ( tableName : string , options ?: QueryOptions ) : Promise < unknown > {
364373 const tableFullName = `${
365374 this . config ?. catalog ? `${ this . config . catalog } .` : ''
366375 } ${ tableName } `;
@@ -392,10 +401,7 @@ export class DatabricksDriver extends JDBCDriver {
392401 }
393402 }
394403
395- /**
396- * @override
397- */
398- protected async getCustomClassPath ( ) {
404+ protected override async getCustomClassPath ( ) {
399405 return resolveJDBCDriver ( ) ;
400406 }
401407
0 commit comments