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


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/tools/metatool/MetaToolTaskDedupColumns.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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;
+           }
+           if (progress.get() != null) {
+             System.out.println(progress.get());
+           }
+         }
+       });
+       daemon.setDaemon(true);
+       daemon.start();
+    }

Review Comment:
   The `if (isVerbose)` block has incorrect indentation (and a whitespace-only 
line) which will fail the standalone-metastore Checkstyle `Indentation` rule. 
Re-indent the block and remove trailing whitespace.



##########
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestHMSColumnDescriptorReuse.java:
##########
@@ -166,6 +173,57 @@ public void testNoReusableColumnDescriptors() throws 
MetaException, InvalidObjec
     assertEquals(3, countColumnDescriptors());
   }
 
+  @Test
+  public void testDeduplicateColumnDescriptorsTool() throws Exception {
+    MetastoreConf.setBoolVar(conf, 
MetastoreConf.ConfVars.PARTITION_REUSE_COLUMN_DESCRIPTORS, false);
+
+    FieldSchema id = new FieldSchema("id", ColumnType.STRING_TYPE_NAME, "");
+    FieldSchema fname = new FieldSchema("fname", ColumnType.STRING_TYPE_NAME, 
"");
+    FieldSchema country = new FieldSchema("country", 
ColumnType.STRING_TYPE_NAME, "");
+
+    Table tbl1 = newTable(Arrays.asList(id, fname), 
Collections.singletonList(country));
+    objectStore.createTable(tbl1);
+    objectStore.addPartition(newPart(tbl1, "US"));
+    objectStore.addPartition(newPart(tbl1, "Greece"));
+    int cdsBeforeDedup = countColumnDescriptors();
+    assertTrue(cdsBeforeDedup == 1);
+
+    AtomicReference<String> progress = new AtomicReference<>();
+    MetaToolObjectStore metaToolStore = new MetaToolObjectStore();
+    metaToolStore.setConf(conf);
+    MetaToolObjectStore.DedupColumnsResult result =
+        metaToolStore.dedupColumns(null, "default", "person", progress, false, 
false);
+    assertEquals(0, result.getTablesWithDuplicates());
+
+    FieldSchema lname = new FieldSchema("lname", ColumnType.STRING_TYPE_NAME, 
"");
+    Table tbl2 = newTable(Arrays.asList(id, fname, lname), 
Collections.singletonList(country));
+    objectStore.alterTable(DEFAULT_CATALOG_NAME, tbl1.getDbName(), 
tbl1.getTableName(), tbl2, null);
+    objectStore.addPartition(newPart(tbl2, "Italy"));
+    objectStore.addPartition(newPart(tbl1, "Germany"));
+    objectStore.addPartition(newPart(tbl1, "Belgium"));
+    objectStore.addPartition(newPart(tbl2, "England"));
+    cdsBeforeDedup = countColumnDescriptors();
+    assertTrue(cdsBeforeDedup > 2);
+
+    result = metaToolStore.dedupColumns(null, "default", "person", progress, 
false, false);
+    assertTrue(result.getStorageDescriptorsUpdated() > 0);
+    assertEquals(2, countColumnDescriptors());
+    assertNotNull(progress.get());
+
+    Deadline.registerIfNot(30 * 1000);
+    Deadline.startTimer("testDeduplicateColumnDescriptorsTool");
+    GetPartitionsByNamesRequest request = new 
GetPartitionsByNamesRequest("default", "person");
+    request.setNames(List.of("country=Germany", "country=Belgium", 
"country=Greece", "country=US"));
+    List<Partition> partitions = objectStore.getPartitionsByNames("hive", 
"default", "person", GetPartitionsArgs.from(request));

Review Comment:
   This line exceeds the standalone-metastore Checkstyle `LineLength` limit 
(120) and will fail the build. Wrap the `getPartitionsByNames` call (and avoid 
hardcoding the catalog when `DEFAULT_CATALOG_NAME` is already imported).
   
   This issue also appears on line 222 of the same file.



##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/tools/metatool/MetaToolTaskDedupColumns.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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;
+           }
+           if (progress.get() != null) {
+             System.out.println(progress.get());
+           }
+         }
+       });
+       daemon.setDaemon(true);
+       daemon.start();
+    }
+    MetaToolObjectStore.DedupColumnsResult result =
+        getObjectStore().dedupColumns(catalogFilter, dbFilter, tableFilter, 
progress, isDryRun, isVerbose);
+    printSummary(result, isDryRun, isVerbose);
+    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:
   This throw statement line exceeds the standalone-metastore Checkstyle 
`LineLength` limit (120) and will fail the build. Wrap it across multiple lines.



##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/tools/metatool/HiveMetaToolCommandLine.java:
##########
@@ -201,9 +222,18 @@ private void parseCommandLine(String[] args) throws 
ParseException {
               diffExtTblLocsParams.length + " arguments");
     }
 
-    if ((dryRun || serdePropKey != null || tablePropKey != null) && 
!isUpdateLocation()) {
-      throw new IllegalArgumentException("-dryRun, -serdePropKey, 
-tablePropKey may be used only for the " +
-          "-updateLocation command");
+    if ((dryRun || serdePropKey != null || tablePropKey != null) && 
!isUpdateLocation()
+        && !isDedupColumns()) {
+      throw new IllegalArgumentException("-dryRun, -serdePropKey, 
-tablePropKey may be used only for the "
+          + "-updateLocation or -dedupColumns commands");
+    }
+
+    if ((serdePropKey != null || tablePropKey != null) && !isUpdateLocation()) 
{
+      throw new IllegalArgumentException("-serdePropKey, -tablePropKey may be 
used only for the -updateLocation command");
+    }

Review Comment:
   This exception message line exceeds the standalone-metastore Checkstyle 
`LineLength` limit (120) and will fail the build. Wrap the 
`IllegalArgumentException` construction across lines.



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