You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ha...@apache.org on 2013/08/13 14:57:17 UTC

svn commit: r1513465 - /hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java

Author: hashutosh
Date: Tue Aug 13 12:57:17 2013
New Revision: 1513465

URL: http://svn.apache.org/r1513465
Log:
HIVE-4885 : Alternative object serialization for execution plan in hive testing  (Xuefu Zhang via Ashutosh Chauhan)

Modified:
    hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java

Modified: hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java?rev=1513465&r1=1513464&r2=1513465&view=diff
==============================================================================
--- hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java (original)
+++ hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java Tue Aug 13 12:57:17 2013
@@ -891,6 +891,8 @@ public class QTestUtil {
           "<string>[0-9]{10}</string>",
           "<string>/.*/warehouse/.*</string>"
       };
+      
+      fixXml4JDK7(outf.getPath());
       maskPatterns(patterns, outf.getPath());
 
       int exitVal = executeDiffCommand(outf.getPath(), planFile, true, false);
@@ -941,6 +943,101 @@ public class QTestUtil {
    return ret;
   }
 
+  /**
+   * Fix the XML generated by JDK7 which is slightly different from what's generated by JDK6,
+   * causing 40+ test failures. There are mainly two problems:
+   * 
+   * 1. object element's properties, id and class, are in reverse order, i.e.
+   *    <object class="org.apache.hadoop.hive.ql.exec.MapRedTask" id="MapRedTask0">
+   *    which needs to be fixed to 
+   *    <object id="MapRedTask0" class="org.apache.hadoop.hive.ql.exec.MapRedTask">
+   * 2. JDK introduces Enum as class, i.e.
+   *    <object id="GenericUDAFEvaluator$Mode0" class="java.lang.Enum">
+   *      <class>org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator$Mode</class>
+   *    which needs to be fixed to
+   *    <object id="GenericUDAFEvaluator$Mode0" class="org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator$Mode"
+   *     method="valueOf">
+   *    
+   * Though not elegant, this allows these test cases to pass until we have a better serialization mechanism.
+   * 
+   * Did I mention this is test code?
+   *    
+   * @param fname the name of the file to fix
+   * @throws Exception in case of IO error
+   */
+  private static void fixXml4JDK7(String fname) throws Exception {
+    String version = System.getProperty("java.version");
+    if (!version.startsWith("1.7")) {
+      return;
+    }
+    
+    BufferedReader in = new BufferedReader(new FileReader(fname));
+    BufferedWriter out = new BufferedWriter(new FileWriter(fname + ".orig"));
+    String line = null;
+    while (null != (line = in.readLine())) {
+      out.write(line);
+      out.write('\n');
+    }
+    in.close();
+    out.close();
+
+    in = new BufferedReader(new FileReader(fname + ".orig"));
+    out = new BufferedWriter(new FileWriter(fname));
+    
+    while (null != (line = in.readLine())) {
+      if (line.indexOf("<object ") == -1 || line.indexOf("class=") == -1) {
+        out.write(line);
+      } else {
+        StringBuilder sb = new StringBuilder();
+        String prefix = line.substring(0, line.indexOf("<object") + 7);
+        sb.append( prefix );
+        String postfix = line.substring(line.lastIndexOf('"') + 1);
+        String id = getPropertyValue(line, "id");
+        if (id != null)
+          sb.append(" id=" + id);
+        String cls = getPropertyValue(line, "class");
+        assert(cls != null);
+        if (cls.equals("\"java.lang.Enum\"")) {
+          line = in.readLine();
+          cls = "\"" + getElementValue(line, "class") + "\"";
+          sb.append(" class=" + cls + " method=\"valueOf\"" );
+        } else {
+          sb.append(" class=" + cls);
+        }
+
+        sb.append(postfix);
+        out.write(sb.toString());
+      } 
+      
+      out.write('\n');
+    }
+
+    in.close();
+    out.close();
+  }
+  
+  /**
+   * Get the value of a property in line. The returned value has original quotes
+   */
+  private static String getPropertyValue(String line, String name) {
+    int start = line.indexOf( name + "=" );
+    if (start == -1)
+      return null;
+    start += name.length() + 1;
+    int end = line.indexOf("\"", start + 1);
+    return line.substring( start, end + 1 );
+  }
+  
+  /**
+   * Get the value of the element in input. (Note: the returned value has no quotes.)
+   */
+  private static String getElementValue(String line, String name) {
+    assert(line.indexOf("<" + name + ">") != -1);
+    int start = line.indexOf("<" + name + ">") + name.length() + 2;
+    int end = line.indexOf("</" + name + ">");
+    return line.substring(start, end);
+  }
+
   private void maskPatterns(String[] patterns, String fname) throws Exception {
     String maskPattern = "#### A masked pattern was here ####";