File tree Expand file tree Collapse file tree
packages/cubejs-databricks-jdbc-driver/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -923,7 +923,7 @@ export class DatabricksDriver extends JDBCDriver {
923923 params ,
924924 ) ;
925925 } finally {
926- await this . query ( `DROP TABLE IF EXISTS ${ tableFullName } _tmp;` , [ ] ) ;
926+ await this . dropTableWithRetry ( ` ${ tableFullName } _tmp` ) ;
927927 }
928928 }
929929
@@ -962,7 +962,25 @@ export class DatabricksDriver extends JDBCDriver {
962962 [ ] ,
963963 ) ;
964964 } finally {
965- await this . query ( `DROP TABLE IF EXISTS ${ tableFullName } _tmp;` , [ ] ) ;
965+ await this . dropTableWithRetry ( `${ tableFullName } _tmp` ) ;
966+ }
967+ }
968+
969+ /**
970+ * Drops a table, retrying with explicit catalog qualification if needed.
971+ * Works around Unity Catalog / Hive Metastore interaction issues where
972+ * DROP TABLE IF EXISTS may fail with TABLE_OR_VIEW_NOT_FOUND.
973+ */
974+ private async dropTableWithRetry ( tableName : string ) : Promise < void > {
975+ try {
976+ await this . query ( `DROP TABLE IF EXISTS ${ tableName } ;` , [ ] ) ;
977+ } catch ( e : any ) {
978+ // Unity Catalog may throw TABLE_OR_VIEW_NOT_FOUND even with IF EXISTS
979+ // when the table doesn't exist or wasn't created. This is safe to ignore.
980+ if ( e . message ?. includes ( 'TABLE_OR_VIEW_NOT_FOUND' ) ) {
981+ return ;
982+ }
983+ throw e ;
966984 }
967985 }
968986}
You can’t perform that action at this time.
0 commit comments