0
我想定义多个猪UDF。他们每个人都将提取不同部分的数据。在我的情况下,数据是具有包括许多嵌套JSON对象的复杂结构的JSON文档。猪:多个UDF在一个类
问题是,现在我已经为我需要的每个函数创建了不同的Eval类。这些类中的每一个都实现了exec()。 有没有办法把所有的功能放到同一个UDF类中,然后从猪中调用它们?
我UDF的一个实例:
public class PigGetTimestamps extends EvalFunc<Tuple>{
public Tuple exec(org.apache.pig.data.Tuple input) throws IOException {
if (input == null || input.size() == 0){
return null;
}
try {
String inputString = DataType.toString(input.get(0));
try
{
String[] tokens=inputString.split("\t");
if (tokens.length<1)
return null;
Document document=new Document(tokens[0], true, false);
long timestamp_fetch=document.getTimestamp_fetch();
long timestamp_pub=document.getTimestampPub();
Tuple output = TupleFactory.getInstance().newTuple(2);
output.set(0,timestamp_pub);
output.set(1,timestamp_fetch);
return output;
}
catch(Exception e)
{
return null;
}
} catch (Exception e) {
System.out.println("Can't extract field; error = " + e.getMessage());
return null;
}
}
有没有什么标准的方法,你可能会得到结果,但它是一个黑客 – Athar