hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sp...@apache.org
Subject [24/50] [abbrv] hive git commit: HIVE-10657 Remove copyBytes operation from MD5 UDF (Alexander Pivovarov, reviewed by Jason Dere)
Date Wed, 20 May 2015 16:01:43 GMT
HIVE-10657 Remove copyBytes operation from MD5 UDF (Alexander Pivovarov, reviewed by Jason
Dere)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/bf7810ab
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/bf7810ab
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/bf7810ab

Branch: refs/heads/parquet
Commit: bf7810ab64caabc47d4370d04f80c0c1f182426a
Parents: ad62e2e
Author: Alexander Pivovarov <apivovarov@gmail.com>
Authored: Fri May 8 11:36:47 2015 -0700
Committer: Alexander Pivovarov <apivovarov@gmail.com>
Committed: Fri May 15 10:20:32 2015 -0700

----------------------------------------------------------------------
 .../org/apache/hadoop/hive/ql/udf/UDFMd5.java   | 33 +++++++++++++-------
 1 file changed, 21 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/bf7810ab/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMd5.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMd5.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMd5.java
index 62c16c2..14928ef 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMd5.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMd5.java
@@ -18,7 +18,10 @@
 
 package org.apache.hadoop.hive.ql.udf;
 
-import org.apache.commons.codec.digest.DigestUtils;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+import org.apache.commons.codec.binary.Hex;
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDF;
 import org.apache.hadoop.io.BytesWritable;
@@ -39,6 +42,15 @@ import org.apache.hadoop.io.Text;
 public class UDFMd5 extends UDF {
 
   private final Text result = new Text();
+  private final MessageDigest digest;
+
+  public UDFMd5() {
+    try {
+      digest = MessageDigest.getInstance("MD5");
+    } catch (NoSuchAlgorithmException e) {
+      throw new RuntimeException(e);
+    }
+  }
 
   /**
    * Convert String to md5
@@ -48,8 +60,10 @@ public class UDFMd5 extends UDF {
       return null;
     }
 
-    String str = n.toString();
-    String md5Hex = DigestUtils.md5Hex(str);
+    digest.reset();
+    digest.update(n.getBytes(), 0, n.getLength());
+    byte[] md5Bytes = digest.digest();
+    String md5Hex = Hex.encodeHexString(md5Bytes);
 
     result.set(md5Hex);
     return result;
@@ -63,17 +77,12 @@ public class UDFMd5 extends UDF {
       return null;
     }
 
-    byte[] bytes = copyBytes(b);
-    String md5Hex = DigestUtils.md5Hex(bytes);
+    digest.reset();
+    digest.update(b.getBytes(), 0, b.getLength());
+    byte[] md5Bytes = digest.digest();
+    String md5Hex = Hex.encodeHexString(md5Bytes);
 
     result.set(md5Hex);
     return result;
   }
-
-  protected byte[] copyBytes(BytesWritable b) {
-    int size = b.getLength();
-    byte[] result = new byte[size];
-    System.arraycopy(b.getBytes(), 0, result, 0, size);
-    return result;
-  }
 }


Mime
View raw message