0
複数のPig UDFを定義したい。それぞれがデータの異なる部分を抽出します。私の場合、データは、多数のネストされたJSONオブジェクトを含む複雑な構造を持つJSONドキュメントです。豚:1つのクラスの複数のUDF
問題は今のところ私が必要とするすべての機能に対して異なるEvalクラスを作成したことです。これらのクラスはそれぞれexec()を実装しています。 すべての関数を同じUDFクラスに入れてブタから呼び出す方法はありますか?私のUDFの1の
例:
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