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