Skip to content

Commit 60d8cf3

Browse files
author
Hongdan Zhu
committed
HIVE-28655: Implement HMS Related Drop Stats Changes, Reset COLUMN_STAT_ACCURATE After Dropping
1 parent 063cfa3 commit 60d8cf3

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7431,6 +7431,8 @@ public boolean delete_column_statistics_req(DeleteColumnStatisticsRequest req) t
74317431
if (!isPartitioned || req.isTableLevel()) {
74327432
ret = rawStore.deleteTableColumnStatistics(parsedDbName[CAT_NAME], parsedDbName[DB_NAME], tableName, colNames, engine);
74337433
if (ret) {
7434+
// remove the deleted column names in parameter COLUMN_STATS_ACCURATE
7435+
StatsSetupConst.removeColumnStatsState(table.getParameters(), colNames);
74347436
eventType = EventType.DELETE_TABLE_COLUMN_STAT;
74357437
for (String colName :
74367438
colNames == null ? table.getSd().getCols().stream().map(FieldSchema::getName).collect(Collectors.toList()) : colNames) {
@@ -7460,6 +7462,10 @@ public boolean delete_column_statistics_req(DeleteColumnStatisticsRequest req) t
74607462
.collect(Collectors.toList()) : colNames) {
74617463
for (String partName : partNames) {
74627464
List<String> partVals = getPartValsFromName(table, partName);
7465+
Partition partition = rawStore.getPartition(parsedDbName[CAT_NAME], parsedDbName[DB_NAME], tableName, partVals);
7466+
Map<String, String> partParams = partition.getParameters();
7467+
// remove the deleted column names in parameter COLUMN_STATS_ACCURATE
7468+
StatsSetupConst.removeColumnStatsState(partParams, colNames);
74637469
if (transactionalListeners != null && !transactionalListeners.isEmpty()) {
74647470
MetaStoreListenerNotifier.notifyEvent(transactionalListeners, eventType,
74657471
new DeletePartitionColumnStatEvent(parsedDbName[CAT_NAME], parsedDbName[DB_NAME], tableName,

standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3242,6 +3242,34 @@ public void deleteColumnStatsState(long tbl_id) throws MetaException {
32423242
}
32433243
}
32443244

3245+
/**
3246+
public Long getTableId(String dbName, String tableName) throws MetaException {
3247+
String queryText;
3248+
Long result;
3249+
switch (dbType.dbType) {
3250+
case MYSQL:
3251+
case POSTGRES:
3252+
case DERBY:
3253+
default:
3254+
// @formatter:off
3255+
queryText = ""
3256+
+ "select t.\"TBL_ID\" from " + TBLS + " t "
3257+
+ " join " + DBS + " d on t.\"DB_ID\" = d.\"DB_ID\" "
3258+
+ " where "
3259+
+ " d.\"NAME\" = " + dbName
3260+
+ " and t.\"TBL_NAME\" = " + tableName;
3261+
// @formatter:on
3262+
}
3263+
try (QueryWrapper query = new QueryWrapper(pm.newQuery("javax.jdo.query.SQL", queryText))) {
3264+
result = executeWithArray(query.getInnerQuery(), null, queryText);
3265+
} catch (Throwable t) {
3266+
throw new MetaException("Failed to fetch table ID: " + t.getMessage());
3267+
}
3268+
return result;
3269+
}
3270+
**/
3271+
3272+
32453273
public boolean deleteTableColumnStatistics(long tableId, List<String> colNames, String engine) {
32463274
String deleteSql = "delete from " + TAB_COL_STATS + " where \"TBL_ID\" = " + tableId;
32473275
if (colNames != null && !colNames.isEmpty()) {

standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,6 +1863,10 @@ public void testColumnStatistics() throws Throwable {
18631863
// multiple columns
18641864
request.setCol_names(Arrays.asList(colName));
18651865
assertTrue(client.deleteColumnStatistics(request));
1866+
Map<String, String> tableParams = client.getTable(dbName, tblName).getParameters();
1867+
String table_column_stats_accurate = tableParams.get("COLUMN_STATS_ACCURATE");
1868+
assertTrue(table_column_stats_accurate == null ||
1869+
(!table_column_stats_accurate.contains(colName[0]) && !table_column_stats_accurate.contains(colName[1])));
18661870
colStats3 = client.getTableColumnStatistics(
18671871
dbName, tblName, Lists.newArrayList(colName), ENGINE);
18681872
assertTrue("stats are not empty: " + colStats3, colStats3.isEmpty());

0 commit comments

Comments
 (0)