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


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java:
##########
@@ -3362,95 +3362,84 @@ private void updateStatsForTruncate(Map<String,String> 
props, EnvironmentContext
     return;
   }
 
-  private void alterPartitionForTruncate(RawStore ms, String catName, String 
dbName, String tableName,
-                                         Table table, Partition partition, 
String validWriteIds, long writeId) throws Exception {
+  private void alterPartitionsForTruncate(RawStore ms, String catName, String 
dbName, String tableName,
+      Table table, List<Partition> partitions, String validWriteIds, long 
writeId) throws Exception {
     EnvironmentContext environmentContext = new EnvironmentContext();
-    updateStatsForTruncate(partition.getParameters(), environmentContext);
-
-    if (!transactionalListeners.isEmpty()) {
-      MetaStoreListenerNotifier.notifyEvent(transactionalListeners,
-          EventType.ALTER_PARTITION,
-          new AlterPartitionEvent(partition, partition, table, true, true,
-              writeId, this));
+    if (partitions.isEmpty()) {
+      return;
     }
-
-    if (!listeners.isEmpty()) {
-      MetaStoreListenerNotifier.notifyEvent(listeners,
-          EventType.ALTER_PARTITION,
-          new AlterPartitionEvent(partition, partition, table, true, true,
-              writeId, this));
+    List<List<String>> partValsList = new ArrayList<>();
+    for (Partition partition: partitions) {
+      updateStatsForTruncate(partition.getParameters(), environmentContext);
+      if (writeId > 0) {
+        partition.setWriteId(writeId);
+      }
+      partition.putToParameters(hive_metastoreConstants.DDL_TIME, 
Long.toString(System
+          .currentTimeMillis() / 1000));
+      partValsList.add(partition.getValues());
+    }
+    ms.alterPartitions(catName, dbName, tableName, partValsList, partitions, 
writeId, validWriteIds);
+    if (transactionalListeners != null && !transactionalListeners.isEmpty()) {
+      boolean shouldSendSingleEvent = MetastoreConf.getBoolVar(this.getConf(),
+          MetastoreConf.ConfVars.NOTIFICATION_ALTER_PARTITIONS_V2_ENABLED);
+      if (shouldSendSingleEvent) {
+        MetaStoreListenerNotifier.notifyEvent(transactionalListeners, 
EventMessage.EventType.ALTER_PARTITIONS,
+            new AlterPartitionsEvent(partitions, partitions, table, true, 
true, this), environmentContext);
+      } else {
+        for (Partition partition : partitions) {
+          MetaStoreListenerNotifier.notifyEvent(transactionalListeners, 
EventMessage.EventType.ALTER_PARTITION,
+              new AlterPartitionEvent(partition, partition, table, true, true, 
partition.getWriteId(), this),
+              environmentContext);
+        }
+      }
     }
-
-    if (writeId > 0) {
-      partition.setWriteId(writeId);
+    if (listeners != null && !listeners.isEmpty()) {
+      boolean shouldSendSingleEvent = MetastoreConf.getBoolVar(this.getConf(),
+          MetastoreConf.ConfVars.NOTIFICATION_ALTER_PARTITIONS_V2_ENABLED);
+      if (shouldSendSingleEvent) {
+        MetaStoreListenerNotifier.notifyEvent(listeners, 
EventMessage.EventType.ALTER_PARTITIONS,
+            new AlterPartitionsEvent(partitions, partitions, table, true, 
true, this), environmentContext);
+      } else {
+        for (Partition partition : partitions) {
+          MetaStoreListenerNotifier.notifyEvent(listeners, 
EventMessage.EventType.ALTER_PARTITION,
+              new AlterPartitionEvent(partition, partition, table, true, true, 
partition.getWriteId(), this),
+              environmentContext);
+        }
+      }
     }
-    alterHandler.alterPartition(ms, wh, catName, dbName, tableName, null, 
partition,
-        environmentContext, this, validWriteIds);
   }
 
   private void alterTableStatsForTruncate(RawStore ms, String catName, String 
dbName,
-                                          String tableName, Table table, 
List<String> partNames,
-                                          String validWriteIds, long writeId) 
throws Exception {
-    if (partNames == null) {
-      if (0 != table.getPartitionKeysSize()) {
-        for (Partition partition : ms.getPartitions(catName, dbName, 
tableName, -1)) {
-          alterPartitionForTruncate(ms, catName, dbName, tableName, table, 
partition,
-              validWriteIds, writeId);
-        }
-      } else {
-        EnvironmentContext environmentContext = new EnvironmentContext();
-        updateStatsForTruncate(table.getParameters(), environmentContext);
-
-        boolean isReplicated = isDbReplicationTarget(ms.getDatabase(catName, 
dbName));
-        if (!transactionalListeners.isEmpty()) {
-          MetaStoreListenerNotifier.notifyEvent(transactionalListeners,
-              EventType.ALTER_TABLE,
-              new AlterTableEvent(table, table, true, true,
-                  writeId, this, isReplicated));
-        }
-
-        if (!listeners.isEmpty()) {
-          MetaStoreListenerNotifier.notifyEvent(listeners,
-              EventType.ALTER_TABLE,
-              new AlterTableEvent(table, table, true, true,
-                  writeId, this, isReplicated));
-        }
-
-        // TODO: this should actually pass thru and set writeId for txn stats.
-        if (writeId > 0) {
-          table.setWriteId(writeId);
-        }
-        alterHandler.alterTable(ms, wh, catName, dbName, tableName, table,
-            environmentContext, this, validWriteIds);
-      }
+      String tableName, Table table, List<Partition> partitionsList,
+      String validWriteIds, long writeId) throws Exception {
+    if (0 != table.getPartitionKeysSize()) {
+      alterPartitionsForTruncate(ms, catName, dbName, tableName, table, 
partitionsList,
+          validWriteIds, writeId);
     } else {
-      for (Partition partition : ms.getPartitionsByNames(catName, dbName, 
tableName, partNames)) {
-        alterPartitionForTruncate(ms, catName, dbName, tableName, table, 
partition,
-            validWriteIds, writeId);
+      EnvironmentContext environmentContext = new EnvironmentContext();
+      updateStatsForTruncate(table.getParameters(), environmentContext);
+      
environmentContext.putToProperties(hive_metastoreConstants.IS_TRUNCATE_OP, 
Boolean.TRUE.toString());
+
+      // TODO: this should actually pass thru and set writeId for txn stats.
+      if (writeId > 0) {
+        table.setWriteId(writeId);
       }
+      alterHandler.alterTable(ms, wh, catName, dbName, tableName, table,

Review Comment:
   nit: cloud we also call `ms.alterTable` directly for truncating the table? 
so we don't need to update the column statistics in alterHandler and using the 
`IS_TRUNCATE_OP` to flag the operation. Rest looks good to me.



-- 
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: gitbox-unsubscr...@hive.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org
For additional commands, e-mail: gitbox-h...@hive.apache.org

Reply via email to