【发布时间】:2016-12-04 00:22:01
【问题描述】:
这里是 UDF 代码
package myudf;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.pig.EvalFunc;
import org.apache.pig.data.Tuple;
public class DateFormat extends EvalFunc<String> {
public String exec(Tuple input) throws IOException {
if (input == null || input.size() == 0) {
return null;
}
try {
String dateStr = (String)input.get(0);
SimpleDateFormat readFormat = new SimpleDateFormat( "MM/dd/yyyy hh:mm:ss.SSS aa");
SimpleDateFormat writeFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss.SSS");
Date date = null;
try {
date = readFormat.parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
}
return writeFormat.format(date).toString();
} catch(Exception e) {
throw new IOException("Caught exception processing input row ", e);
}
}
}
导出了一个 Jar 并在 grunt 中注册
Register /local/path/to/UDFDate.jar;
A = LOAD 'hdfs date file';
B = FOREACH A GENERATE UDFDate.myudf.DateFormat($0);
报错
[main] 错误 org.apache.pig.tools.grunt.Grunt - 错误 1070:不能 使用导入解析 UDFDate.DateFormat:[, java.lang., org.apache.pig.builtin., org.apache.pig.impl.builtin.]
【问题讨论】:
-
什么是myudf。你的包 UDFDate 中有 java 文件 myudf 吗?
-
DateFormat.java文件的第一行是什么? -
对不起伙计们..我错过了包名..
标签: java apache-pig udf