我正在尝试编译这个 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;
}
}
尝试编译:
javac Md5.java
但我得到:
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;
我假设这些在某处的 jar 文件中,但我不确定 hadoop 将它们安装到哪里,所以我无法将它们添加到我的类路径中。有谁知道默认位置或如何找出?