You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by sz...@apache.org on 2014/11/17 23:43:58 UTC

svn commit: r1640249 - /hive/branches/spark/ql/src/test/org/apache/hadoop/hive/ql/exec/spark/TestHiveKVResultCache.java

Author: szehon
Date: Mon Nov 17 22:43:58 2014
New Revision: 1640249

URL: http://svn.apache.org/r1640249
Log:
HIVE-8882 : Fix test TestHiveKVResultCache [Spark Branch] (Jimmy Xiang via Szehon)

Modified:
    hive/branches/spark/ql/src/test/org/apache/hadoop/hive/ql/exec/spark/TestHiveKVResultCache.java

Modified: hive/branches/spark/ql/src/test/org/apache/hadoop/hive/ql/exec/spark/TestHiveKVResultCache.java
URL: http://svn.apache.org/viewvc/hive/branches/spark/ql/src/test/org/apache/hadoop/hive/ql/exec/spark/TestHiveKVResultCache.java?rev=1640249&r1=1640248&r2=1640249&view=diff
==============================================================================
--- hive/branches/spark/ql/src/test/org/apache/hadoop/hive/ql/exec/spark/TestHiveKVResultCache.java (original)
+++ hive/branches/spark/ql/src/test/org/apache/hadoop/hive/ql/exec/spark/TestHiveKVResultCache.java Mon Nov 17 22:43:58 2014
@@ -121,8 +121,8 @@ public class TestHiveKVResultCache {
     HashSet<Long> primaryRowKeys = new HashSet<Long>();
     HashSet<Long> separateRowKeys = new HashSet<Long>();
     for (Tuple2<HiveKey, BytesWritable> item: output) {
-      String key = new String(item._1.getBytes());
-      String value = new String(item._2.getBytes());
+      String key = bytesWritableToString(item._1);
+      String value = bytesWritableToString(item._2);
       String prefix = key.substring(0, key.indexOf('_'));
       Long id = Long.valueOf(key.substring(5 + prefix.length()));
       if (prefix.equals(prefix1)) {
@@ -139,6 +139,18 @@ public class TestHiveKVResultCache {
     assertEquals(primaryRows, primaryRowKeys.size());
   }
 
+  /**
+   * Convert a BytesWritable to a string.
+   * Don't use {@link BytesWritable#copyBytes()}
+   * so as to be compatible with hadoop 1
+   */
+  private static String bytesWritableToString(BytesWritable bw) {
+    int size = bw.getLength();
+    byte[] bytes = new byte[size];
+    System.arraycopy(bw.getBytes(), 0, bytes, 0, size);
+    return new String(bytes);
+  }
+
   private static class MyHiveFunctionResultList extends HiveBaseFunctionResultList {
     private static final long serialVersionUID = -1L;