【发布时间】:2018-09-05 18:29:03
【问题描述】:
我已经创建了下面的 UDF 函数:
package co.hive.udf;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.*;
import org.apache.hadoop.hive.ql.exec.UDF;
public class encryptHivecolumn extends UDF {
private static final String ALGO = "AES";
private static final byte[] keyValue =
new byte[] { 'T', 'h', 'e', 'B', 'e', 's', 't',
'S', 'e', 'c', 'r','e', 't', 'K', 'e', 'y' };
public static String encrypt(String Data) throws Exception {
Key key = generateKey();
Cipher c = Cipher.getInstance(ALGO);
c.init(Cipher.ENCRYPT_MODE, key);
byte[] encVal = c.doFinal(Data.getBytes());
@SuppressWarnings("restriction")
String encryptedValue = new BASE64Encoder().encode(encVal);
return encryptedValue;
}
private static Key generateKey() throws Exception {
Key key = new SecretKeySpec(keyValue, ALGO);
return key;
}
}
并从 Eclipse 创建 JAR。我也从 eclipse 添加了 JAR 文件,它说添加到类路径,但是当我创建临时函数时,它说找不到类。
【问题讨论】:
-
您是否创建了一个胖罐子(包含所有依赖项的罐子)或厚罐子。如果您不确定我在说什么,请检查罐子的大小。如果它在 KB 中,它没有必要的依赖,如果它在 MB 中,那么你很高兴。
-
你能粘贴一个堆栈跟踪,还有你是如何添加 jar 的
-
我能够创建 JAR 并运行它,但现在我遇到了错误。如果我只是运行 select 语句,那么它是正确加密的,但是当我从 select 创建表时,它会在表中插入 NULL 值。请参阅下面的详细信息。如何避免在 create table as 语句中列出现 null 的问题。
标签: class hive user-defined-functions