You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2021/01/04 07:49:50 UTC

[GitHub] [hive] pkumarsinha commented on a change in pull request #1768: HIVE-24526: Get grouped locations of external table data using metatool.

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



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