java 如何编译 Hive UDF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11019465/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I compile a Hive UDF
提问by nickponline
I am trying to compile this UDF:
我正在尝试编译这个 UDF:
package com.dataminelab.hive.udf;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;
import java.security.*;
/**
* Calculate md5 of the string
*/
public final class Md5 extends UDF {
public Text evaluate(final Text s) {
if (s == null) {
return null;
}
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(s.toString().getBytes());
byte[] md5hash = md.digest();
StringBuilder builder = new StringBuilder();
for (byte b : md5hash) {
builder.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1));
}
return new Text(builder.toString());
} catch (NoSuchAlgorithmException nsae) {
System.out.println("Cannot find digest algorithm");
System.exit(1);
}
return null;
}
}
Trying to compile with:
尝试编译:
javac Md5.java
But I get:
但我得到:
Md5.java:2: package org.apache.hadoop.hive.ql.exec does not exist
import org.apache.hadoop.hive.ql.exec.UDF;
^
Md5.java:3: package org.apache.hadoop.io does not exist
import org.apache.hadoop.io.Text;
I assume these are in a jar file somewhere but I'm not sure where hadoop install them to so I can't add them to my classpath. Does anyone know the default location or how to find out?
我假设这些在某个 jar 文件中,但我不确定 hadoop 将它们安装到哪里,所以我无法将它们添加到我的类路径中。有谁知道默认位置或如何找到?
回答by Peter Eisentraut
The following works for me, but I suspect the details will vary depending on your installation and what your source code does:
以下对我有用,但我怀疑细节会因您的安装和源代码的作用而异:
export CLASSPATH=/usr/lib/hive/lib/hive-exec-0.9.0.15.jar:/usr/lib/hadoop/hadoop-core.jar
回答by bhargav
add hive-0.4.1 jar file to lib
将 hive-0.4.1 jar 文件添加到 lib
回答by Girish Rao
Have you included jars of the form $HIVE_HOME/lib/hive-serde-*.jar and $HIVE_HOME/lib/hive-exec-*.jar in your classpath?
您是否在类路径中包含了 $HIVE_HOME/lib/hive-serde-*.jar 和 $HIVE_HOME/lib/hive-exec-*.jar 形式的 jars?