dengzhhu653 commented on code in PR #6126:
URL: https://github.com/apache/hive/pull/6126#discussion_r2438022642


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java:
##########
@@ -1031,61 +1029,28 @@ private Path constructRenamedPath(Path defaultNewPath, 
Path currentPath) {
         defaultNewPath.toUri().getPath());
   }
 
-  public static List<ColumnStatistics> getColumnStats(RawStore msdb, Table 
oldTable)
-      throws NoSuchObjectException, MetaException {
-    String catName = normalizeIdentifier(oldTable.isSetCatName()
-        ? oldTable.getCatName()
-        : getDefaultCatalog(msdb.getConf()));
-    String dbName = oldTable.getDbName().toLowerCase();
-    String tableName = normalizeIdentifier(oldTable.getTableName());
-    List<String> columnNames = 
oldTable.getSd().getCols().stream().map(FieldSchema::getName).collect(Collectors.toList());
-    return msdb.getTableColumnStatistics(catName, dbName, tableName, 
columnNames);
-  }
-
   @VisibleForTesting
-  public static List<ColumnStatistics> deleteTableColumnStats(RawStore msdb, 
Table oldTable, Table newTable, List<ColumnStatistics> multiColStats)
+  public void deleteTableColumnStats(RawStore msdb, Table oldTable, Table 
newTable)
       throws InvalidObjectException, MetaException {
-    List<ColumnStatistics> newMultiColStats = new ArrayList<>();
     try {
       String catName = normalizeIdentifier(oldTable.isSetCatName()
           ? oldTable.getCatName()
           : getDefaultCatalog(msdb.getConf()));
       String dbName = oldTable.getDbName().toLowerCase();
       String tableName = normalizeIdentifier(oldTable.getTableName());
-      String newDbName = newTable.getDbName().toLowerCase();
-      String newTableName = normalizeIdentifier(newTable.getTableName());
       List<FieldSchema> oldTableCols = oldTable.getSd().getCols();
       List<FieldSchema> newTableCols = newTable.getSd().getCols();
-
-      boolean nameChanged = !newDbName.equals(dbName) || 
!newTableName.equals(tableName);
-
-      if ((nameChanged || 
!MetaStoreServerUtils.columnsIncludedByNameType(oldTableCols, newTableCols)) &&
+      if (!columnsIncludedByNameType(oldTableCols, newTableCols) ||
+          !MetaStoreServerUtils.arePrefixColumns(oldTableCols, newTableCols) &&
           // Don't bother in the case of ACID conversion.
           TxnUtils.isAcidTable(oldTable) == TxnUtils.isAcidTable(newTable)) {
-        for (ColumnStatistics colStats : multiColStats) {
-          List<ColumnStatisticsObj> statsObjs = colStats.getStatsObj();
-          List<ColumnStatisticsObj> newStatsObjs = new ArrayList<>();
-
-          if (statsObjs != null) {
-            for (ColumnStatisticsObj statsObj : statsObjs) {
-              boolean found = newTableCols.stream().anyMatch(c -> 
statsObj.getColName().equalsIgnoreCase(c.getName()) &&
-                  statsObj.getColType().equalsIgnoreCase(c.getType()));
-              if (nameChanged || !found) {
-                msdb.deleteTableColumnStatistics(catName, 
oldTable.getDbName().toLowerCase(),
-                    normalizeIdentifier(oldTable.getTableName()), 
statsObj.getColName(), colStats.getEngine());
-              }
-              if (found) {
-                newStatsObjs.add(statsObj);
-              }
-            }
-            StatsSetupConst.removeColumnStatsState(newTable.getParameters(),
-                
statsObjs.stream().map(ColumnStatisticsObj::getColName).collect(Collectors.toList()));
-          }
-          ColumnStatisticsDesc statsDesc = colStats.getStatsDesc();
-          statsDesc.setDbName(newDbName);
-          statsDesc.setTableName(newTableName);
-          colStats.setStatsObj(newStatsObjs);
-          newMultiColStats.add(colStats);
+        List<String> deletedCols = oldTableCols.stream().filter(
+                c -> newTableCols.stream().noneMatch(n -> 
columnsIncludedByNameType(Arrays.asList(c), Arrays.asList(n))))

Review Comment:
   Add a new findStaleColumns method originated from columnsIncludedByNameType



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to