Skip to content

Commit 45fcd92

Browse files
committed
fix(databricks-jdbc-driver): Ignore TABLE_OR_VIEW_NOT_FOUND when dropping export temp tables
1 parent d9ca57c commit 45fcd92

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

packages/cubejs-databricks-jdbc-driver/src/DatabricksDriver.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)