Copilot commented on code in PR #6719:
URL: https://github.com/apache/hive/pull/6719#discussion_r3840759894


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/tools/metatool/MetaToolTaskDedupColumns.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.tools.metatool;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.hadoop.hive.metastore.tools.MetaToolObjectStore;
+
+class MetaToolTaskDedupColumns extends MetaToolTask {
+  @Override
+  void execute() {
+    String[] params = getCl().getDedupColumnsParams();
+    String catalogFilter = params.length > 0 ? params[0] : null;
+    String dbFilter = params.length > 1 ? params[1] : null;
+    String tableFilter = params.length > 2 ? params[2] : null;
+    boolean isDryRun = getCl().isDryRun();
+    boolean isVerbose = getCl().isVerbose();
+    
+    final AtomicReference<String> progress = new AtomicReference<>();
+    AtomicBoolean stopped = new AtomicBoolean(false);
+    Thread daemon = null;
+    if (isVerbose) {
+      daemon = new Thread(() -> {
+        while (!stopped.get()) {
+          try {
+            Thread.sleep(30 * 1000);
+          } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+            break;
+          }
+          String message = progress.get();
+          if (message != null) {
+            System.out.println(message);
+          }
+        }
+      });
+      daemon.setDaemon(true);
+      daemon.start();
+    }
+    MetaToolObjectStore.DedupColumnsResult result;
+    try {
+      result = getObjectStore().dedupColumns(catalogFilter, dbFilter, 
tableFilter, progress, isDryRun, isVerbose);
+      printSummary(result, isDryRun, isVerbose);
+    } finally {
+      if (daemon != null) {
+        stopped.set(true);
+        daemon.interrupt();
+      }
+    }
+    if (daemon != null) {
+      stopped.set(true);
+      daemon.interrupt();
+    }
+    if (result.getException() != null) {
+      throw new IllegalStateException("HiveMetaTool: failed to de-duplicate 
column descriptors for all tables",
+          result.getException());
+    }

Review Comment:
   The daemon shutdown logic is duplicated: the block after the try/finally 
repeats the same stopped/interrupt logic that already runs in the finally. This 
is redundant and makes the control flow harder to follow.



##########
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/tools/metatool/TestHiveMetaToolCommandLine.java:
##########
@@ -132,23 +132,48 @@ public void testDiffExtTblLocsArgCount() throws 
ParseException {
   @Test
   public void testDryRunNotAllowed() throws ParseException {
     exception.expect(IllegalArgumentException.class);
-    exception.expectMessage("-dryRun, -serdePropKey, -tablePropKey may be used 
only for the -updateLocation command");
+    exception.expectMessage("-dryRun, -serdePropKey, -tablePropKey may be used 
only for the "
+        + "-updateLocation or -dedupColumns commands");
 
     new HiveMetaToolCommandLine(new String[] {"-listFSRoot", "-dryRun"});

Review Comment:
   The expected error message in testDryRunNotAllowed no longer matches 
HiveMetaToolCommandLine's updated validation (it now throws an error about 
-dryRun only). This test will fail because it expects the old combined 
"-dryRun, -serdePropKey, -tablePropKey" wording.



-- 
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