You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by br...@apache.org on 2015/01/06 19:34:21 UTC

svn commit: r1649896 - /hive/branches/HIVE-8065/itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java

Author: brock
Date: Tue Jan  6 18:34:21 2015
New Revision: 1649896

URL: http://svn.apache.org/r1649896
Log:
HIVE-9254 - Incompatible output format for prehook according to the encryption changes (Ferdinand Xu via Brock)

Modified:
    hive/branches/HIVE-8065/itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java

Modified: hive/branches/HIVE-8065/itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java
URL: http://svn.apache.org/viewvc/hive/branches/HIVE-8065/itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java?rev=1649896&r1=1649895&r2=1649896&view=diff
==============================================================================
--- hive/branches/HIVE-8065/itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java (original)
+++ hive/branches/HIVE-8065/itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java Tue Jan  6 18:34:21 2015
@@ -40,7 +40,6 @@ import java.io.Serializable;
 import java.io.StringWriter;
 import java.lang.RuntimeException;
 import java.net.URL;
-import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -79,7 +78,6 @@ import org.apache.hadoop.hive.ql.exec.Ta
 import org.apache.hadoop.hive.ql.exec.Utilities;
 import org.apache.hadoop.hive.ql.lockmgr.zookeeper.ZooKeeperHiveLockManager;
 import org.apache.hadoop.hive.ql.metadata.Hive;
-import org.apache.hadoop.hive.ql.metadata.HiveException;
 import org.apache.hadoop.hive.ql.metadata.Table;
 import org.apache.hadoop.hive.ql.parse.ASTNode;
 import org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer;
@@ -113,6 +111,7 @@ public class QTestUtil {
 
   // security property names
   private static final String SECURITY_KEY_PROVIDER_URI_NAME = "dfs.encryption.key.provider.uri";
+  private static final String CRLF = System.getProperty("line.separator");
 
   private static final Log LOG = LogFactory.getLog("QTestUtil");
   private static final String QTEST_LEAVE_FILES = "QTEST_LEAVE_FILES";
@@ -914,25 +913,20 @@ public class QTestUtil {
     }
   }
 
-  private static final String CRLF = System.getProperty("line.separator");
   public int executeClient(String tname1, String tname2) {
-    List<String> commandList = new ArrayList<String>();
-
-    commandList.addAll(getCommands(tname1));
-    commandList.add(CRLF);
-    commandList.addAll(getCommands(tname2));
-
-    return executeClient(commandList);
+    String commands = getCommand(tname1) + CRLF + getCommand(tname2);
+    return executeClientInternal(commands);
   }
 
   public int executeClient(String tname) {
-    return executeClient(getCommands(tname));
+    return executeClientInternal(getCommand(tname));
   }
 
-  public int executeClient(final List<String> commandList) {
+  private int executeClientInternal(String commands) {
+    String [] cmds = commands.split(";");
     int rc = 0;
 
-    for (String command : commandList) {
+    for (String command : cmds) {
       if (isCommandUsedForTesting(command)) {
         rc = executeTestCommand(command);
       } else {
@@ -998,34 +992,19 @@ public class QTestUtil {
     return testCommand != null;
   }
 
-  private List<String> getCommands(final String testName) {
-    List<String> commandList = new ArrayList<String>();
-    String testCommands = qMap.get(testName);
-
-    String command = "";
-    for (String line : testCommands.split("\n")) {
-      line = line.trim();
-
-      if (StringUtils.isBlank(line) || isComment(line)) {
-        continue;
-      }
-
-      // Join multiple line commands into one line
-      if (StringUtils.endsWith(line, "\\")) {
-        command += " " + StringUtils.chop(line);
-        continue;
-      } else if (!StringUtils.endsWith(line, ";")) {
-        command += " " + line;
-        continue;
-      } else {
-        command += " " + line;
-      }
-
-      commandList.add(command.trim());
-      command = "";
-    }
-
-    return commandList;
+  private String getCommand(String tname) {
+    String commands = qMap.get(tname);
+    StringBuilder newCommands = new StringBuilder(commands.length());
+    int lastMatchEnd = 0;
+    Matcher commentMatcher = Pattern.compile("^--.*$", Pattern.MULTILINE).matcher(commands);
+    while (commentMatcher.find()) {
+      newCommands.append(commands.substring(lastMatchEnd, commentMatcher.start()));
+      newCommands.append(commentMatcher.group().replaceAll("(?<!\\\\);", "\\\\;"));
+      lastMatchEnd = commentMatcher.end();
+    }
+    newCommands.append(commands.substring(lastMatchEnd, commands.length()));
+    commands = newCommands.toString();
+    return commands;
   }
 
   private boolean isComment(final String line) {