You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hive.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2021/01/04 07:50:00 UTC

[jira] [Work logged] (HIVE-24526) Get grouped locations of external table data using metatool.

     [ https://issues.apache.org/jira/browse/HIVE-24526?focusedWorklogId=530548&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-530548 ]

ASF GitHub Bot logged work on HIVE-24526:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 04/Jan/21 07:49
            Start Date: 04/Jan/21 07:49
    Worklog Time Spent: 10m 
      Work Description: pkumarsinha commented on a change in pull request #1768:
URL: https://github.com/apache/hive/pull/1768#discussion_r551156543



##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/tools/metatool/MetaToolTaskDiffExtTblLocs.java
##########
@@ -0,0 +1,165 @@
+/*
+ * 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 org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class MetaToolTaskDiffExtTblLocs extends MetaToolTask {
+  private static final Logger LOG = LoggerFactory.getLogger(MetaToolTaskDiffExtTblLocs.class);
+  @Override
+  void execute() {
+    String[] args = getCl().getDiffExtTblLocsParams();
+    try {
+      File file1 = new File(args[0]);
+      File file2 = new File(args[1]);
+      String ouputDir = args[2];

Review comment:
       Validate for args count, print usage message on failure.

##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/tools/metatool/MetaToolTaskDiffExtTblLocs.java
##########
@@ -0,0 +1,165 @@
+/*
+ * 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 org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class MetaToolTaskDiffExtTblLocs extends MetaToolTask {
+  private static final Logger LOG = LoggerFactory.getLogger(MetaToolTaskDiffExtTblLocs.class);
+  @Override
+  void execute() {
+    String[] args = getCl().getDiffExtTblLocsParams();
+    try {
+      File file1 = new File(args[0]);
+      File file2 = new File(args[1]);
+      String ouputDir = args[2];
+      String outFileName = "diff_" + System.currentTimeMillis();
+      System.out.println("Writing diff to " + outFileName);
+      if (!file1.exists()) {
+        System.out.println("Input " + args[0] + " does not exist.");
+        return;
+      }
+      if (!file2.exists()) {
+        System.out.println("Input " + args[1] + " does not exist.");
+        return;
+      }
+      JSONObject jsonObject = getDiffJson(args);
+      FileWriter fw = new FileWriter(ouputDir + "/" + outFileName);
+      PrintWriter pw = new PrintWriter(fw);
+      pw.println(jsonObject.toString(4).replace("\\", ""));
+      pw.close();
+    } catch (Exception e) {
+      LOG.error("Generating diff of external table locations failed: ", e);

Review comment:
       Some of logs are console based, some are in Logger?

##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/tools/metatool/MetaToolTaskDiffExtTblLocs.java
##########
@@ -0,0 +1,165 @@
+/*
+ * 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 org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class MetaToolTaskDiffExtTblLocs extends MetaToolTask {
+  private static final Logger LOG = LoggerFactory.getLogger(MetaToolTaskDiffExtTblLocs.class);
+  @Override
+  void execute() {
+    String[] args = getCl().getDiffExtTblLocsParams();
+    try {
+      File file1 = new File(args[0]);
+      File file2 = new File(args[1]);
+      String ouputDir = args[2];
+      String outFileName = "diff_" + System.currentTimeMillis();
+      System.out.println("Writing diff to " + outFileName);
+      if (!file1.exists()) {
+        System.out.println("Input " + args[0] + " does not exist.");
+        return;
+      }
+      if (!file2.exists()) {
+        System.out.println("Input " + args[1] + " does not exist.");
+        return;
+      }
+      JSONObject jsonObject = getDiffJson(args);
+      FileWriter fw = new FileWriter(ouputDir + "/" + outFileName);
+      PrintWriter pw = new PrintWriter(fw);
+      pw.println(jsonObject.toString(4).replace("\\", ""));
+      pw.close();
+    } catch (Exception e) {
+      LOG.error("Generating diff of external table locations failed: ", e);
+    }
+  }
+
+  private JSONObject getDiffJson(String fileNames[]) throws IOException, JSONException {
+    File file1 = new File(fileNames[0]);
+    File file2 = new File(fileNames[1]);

Review comment:
       This whole thing can be refactored and moved to  a method

##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/tools/metatool/MetaToolTaskDiffExtTblLocs.java
##########
@@ -0,0 +1,165 @@
+/*
+ * 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 org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class MetaToolTaskDiffExtTblLocs extends MetaToolTask {
+  private static final Logger LOG = LoggerFactory.getLogger(MetaToolTaskDiffExtTblLocs.class);
+  @Override
+  void execute() {
+    String[] args = getCl().getDiffExtTblLocsParams();
+    try {
+      File file1 = new File(args[0]);
+      File file2 = new File(args[1]);
+      String ouputDir = args[2];
+      String outFileName = "diff_" + System.currentTimeMillis();
+      System.out.println("Writing diff to " + outFileName);
+      if (!file1.exists()) {
+        System.out.println("Input " + args[0] + " does not exist.");
+        return;
+      }
+      if (!file2.exists()) {
+        System.out.println("Input " + args[1] + " does not exist.");
+        return;
+      }
+      JSONObject jsonObject = getDiffJson(args);
+      FileWriter fw = new FileWriter(ouputDir + "/" + outFileName);
+      PrintWriter pw = new PrintWriter(fw);
+      pw.println(jsonObject.toString(4).replace("\\", ""));
+      pw.close();
+    } catch (Exception e) {
+      LOG.error("Generating diff of external table locations failed: ", e);
+    }
+  }
+
+  private JSONObject getDiffJson(String fileNames[]) throws IOException, JSONException {
+    File file1 = new File(fileNames[0]);

Review comment:
       Already had file handles, why not to pass them and use here?




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

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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 530548)
    Time Spent: 0.5h  (was: 20m)

> Get grouped locations of external table data using metatool.
> ------------------------------------------------------------
>
>                 Key: HIVE-24526
>                 URL: https://issues.apache.org/jira/browse/HIVE-24526
>             Project: Hive
>          Issue Type: Task
>            Reporter: Arko Sharma
>            Assignee: Arko Sharma
>            Priority: Major
>              Labels: pull-request-available
>         Attachments: HIVE-24526.01.patch, HIVE-24526.02.patch, HIVE-24526.03.patch, HIVE-24526.04.patch
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> Add a functionality to metatool to get a list of locations which cover all external-table data-locations for a database specified by user.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)