我想使用 tika 在猪中创建 UDF ,以处理 HDFS 中的图片。
下面是我的代码,但我得到 ClassNotFound 异常
public String exec(Tuple input) throws ExecException, IOException {
try {
if (input == null || input.size() == 0 || input.get(0) == null)
{
return null;
}
} catch (ExecException ex) {
Logger.getLogger(Check.class.getName()).log(Level.SEVERE, null, ex);
}
String s="";
ByteArrayInputStream b = (ByteArrayInputStream)input.get(0);
ContentHandler contenthandler = new BodyContentHandler();
Metadata metadata = new Metadata();
Parser parser = new AutoDetectParser();
ParseContext parseCtx = new ParseContext();
try {
parser.parse(b, contenthandler, metadata,parseCtx);
} catch (SAXException ex) {
Logger.getLogger(Check.class.getName()).log(Level.SEVERE, null, ex);
} catch (TikaException ex) {
Logger.getLogger(Check.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("Mime: " + metadata.get(Metadata.CONTENT_TYPE));
return metadata.get(Metadata.CONTENT_TYPE);
}
输入是以未知格式存储在hdfs中的图像文件。
输出我需要输出作为文件的类型。 但是我得到了TikaException和上面代码的java Class not found。
错误
2014-11-21 12:00:56,417 [main] INFO org.apache.pig.backend.hadoop.executionengi
ne.mapReduceLayer.MapReduceLauncher - Failed!
2014-11-21 12:00:56,483 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 10
66: Unable to open iterator for alias f. Backend error : java.lang.ClassNotFound
Exception: org.apache.tika.exception.TikaException
PigScript
a= load '/image.jpeg' as x;
b= group a all;
f= foreach b generate package.check(a)
如果有人知道上述问题的解决方案。请尽快指导我。
答案 0 :(得分:0)
请检查Apache Tika jar是否已在Pig脚本中注册。确保在执行Pig脚本期间它可用。
前:
REGISTER '/home/user/pig/udfrepository/projectUDF.jar'
REGISTER '/home/user/thridpartyjars/xyz.jar';