Skip to content

Commit 029323e

Browse files
authored
Fixed issue in the previous commit (Optimized delete table in hive using direct-sql). Issue was that in certain hive metastore versions, certain tables exist based on the version or the usage. (Netflix#244)
1 parent 210671d commit 029323e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

metacat-connector-hive/src/main/java/com/netflix/metacat/connector/hive/sql/DirectSqlTable.java

+23
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,26 @@ public void delete(final QualifiedName tableName) {
240240
new SqlParameterValue(Types.BIGINT, ids.getSdsId()));
241241
jdbcTemplate.update(SQL.UPDATE_SDS_SERDE, new SqlParameterValue(Types.BIGINT, null),
242242
new SqlParameterValue(Types.BIGINT, ids.getSdsId()));
243+
//
244+
// Ignore the error. We should be ignoring the error when table does not exist.
245+
// In certain hive metastore versions, these tables might not be present.
246+
// TODO: Better handle this non-existing tables.
247+
//
248+
try {
249+
jdbcTemplate.update(SQL.DELETE_COLUMNS_OLD, new SqlParameterValue(Types.BIGINT, ids.getSdsId()));
250+
} catch (DataAccessException ignored) {
251+
log.debug("Ignore. Probably table COLUMNS_OLD does not exist.");
252+
}
253+
try {
254+
jdbcTemplate.update(SQL.DELETE_TBL_PRIVS, new SqlParameterValue(Types.BIGINT, ids.getTableId()));
255+
} catch (DataAccessException ignored) {
256+
log.debug("Ignore. Probably table TBL_PRIVS does not exist.");
257+
}
258+
try {
259+
jdbcTemplate.update(SQL.DELETE_TBL_COL_PRIVS, new SqlParameterValue(Types.BIGINT, ids.getTableId()));
260+
} catch (DataAccessException ignored) {
261+
log.debug("Ignore. Probably table TBL_COL_PRIVS does not exist.");
262+
}
243263
jdbcTemplate.update(SQL.DELETE_COLUMNS_V2, new SqlParameterValue(Types.BIGINT, ids.getCdId()));
244264
jdbcTemplate.update(SQL.DELETE_CDS, new SqlParameterValue(Types.BIGINT, ids.getCdId()));
245265
jdbcTemplate.update(SQL.DELETE_PARTITION_KEYS, new SqlParameterValue(Types.BIGINT, ids.getTableId()));
@@ -292,6 +312,7 @@ private static class SQL {
292312
static final String INSERT_TABLE_PARAMS =
293313
"insert into TABLE_PARAMS(tbl_id,param_key,param_value) values (?,?,?)";
294314
static final String UPDATE_SDS_CD = "UPDATE SDS SET CD_ID=? WHERE SD_ID=?";
315+
static final String DELETE_COLUMNS_OLD = "DELETE FROM COLUMNS_OLD WHERE SD_ID=?";
295316
static final String DELETE_COLUMNS_V2 = "DELETE FROM COLUMNS_V2 WHERE CD_ID=?";
296317
static final String DELETE_CDS = "DELETE FROM CDS WHERE CD_ID=?";
297318
static final String DELETE_PARTITION_KEYS = "DELETE FROM PARTITION_KEYS WHERE TBL_ID=?";
@@ -308,6 +329,8 @@ private static class SQL {
308329
static final String DELETE_SERDE_PARAMS = "DELETE FROM SERDE_PARAMS WHERE SERDE_ID=?";
309330
static final String DELETE_SERDES = "DELETE FROM SERDES WHERE SERDE_ID=?";
310331
static final String DELETE_SDS = "DELETE FROM SDS WHERE SD_ID=?";
332+
static final String DELETE_TBL_PRIVS = "DELETE FROM TBL_PRIVS WHERE TBL_ID=?";
333+
static final String DELETE_TBL_COL_PRIVS = "DELETE FROM TBL_COL_PRIVS WHERE TBL_ID=?";
311334
static final String DELETE_TBLS = "DELETE FROM TBLS WHERE TBL_ID=?";
312335
static final String TABLE_SEQUENCE_IDS = "select t.tbl_id, s.sd_id, s.cd_id, s.serde_id"
313336
+ " from DBS d join TBLS t on d.db_id=t.db_id join SDS s on t.sd_id=s.sd_id"

0 commit comments

Comments
 (0)