我是猪的新手..并且正在尝试编写一个 udf 函数。
所以基本上这里是问题陈述。
我有一个像这样的虚拟数据..
user_id, movie_id, date_time_stamp
所以我想做的是这个。如果交易是在
9 am and 11 am --> breakfast
and so on
所以这是我的猪脚本
REGISTER path/myudfs.jar
in = LOAD 'path/input' USING
PigStorage('\\u001') AS (user:long,movie:long, time:chararray);
result = foreach in GENERATE myudfs.time(time);
STORE result INTO 'path/output/time' using PigStorage(',');
现在myudf.jar java代码是这样的
public class time extends EvalFunc<String>{
public String exec(Tuple input) throws IOException {
if ((input == null) || (input.size() == 0))
return null;
try{
String time = (String) input.get(0) ;
DateFormat df = new SimpleDateFormat("hh:mm:ss.000");
Date date = df.parse(time);
String timeOfDay = getTimeOfDay(date);
return timeOfDay;
} catch (ParseException e) {
//how will I handle when df.parse(time) fails and throws ParseException?
//maybe:
return null;
}
}
所以它接受元组并返回一个字符串......(我也是java新手......)
在此之后,我尝试将此脚本运行为
pig -f time.pig
它返回一个错误
2012-11-12 08:33:08,214 [main] INFO
org.apache.pig.backend.hadoop.executionengine.HExecutionEngine - Connecting to
hadoop file system at: maprfs:///
2012-11-12 08:33:08,353 [main] INFO
org.apache.pig.backend.hadoop.executionengine.HExecutionEngine - Connecting to
map-reduce job tracker at: maprfs:///
2012-11-12 08:33:08,767 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1069:
Problem resolving class version numbers for class myudfs.time
猪邮件列表上的一些帖子是我的 PIG_CLASSPATH 没有设置,我应该将它指向 /path/hadoop/conf
我做到了.. 所以现在 $echo PIG_CLASSPATH --> /path/hadoop/conf
但我得到同样的错误
请指教。谢谢
编辑 1:在查看日志时,错误跟踪是:
Caused by: java.lang.UnsupportedClassVersionError: myudfs/time : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.apache.pig.impl.PigContext.resolveClassName(PigContext.java:427)
... 27 more
这像java问题吗?