Hive テーブルにロードする前に、フラット ファイルのデータをフォーマットする必要があります。
CF32|4711|00010101Z| +34.883| 98562AS1D |N8594ãä| 00 | 2
ファイルはパイプで区切られており、フラット ファイルのさまざまな列にさまざまなクリーニングおよび書式設定関数を適用する必要があります。Clean_Text、Format_Date、Format_TimeStamp、Format_Integer などの関数が複数あります。
私の考えは、スキーマをコンストラクターとして UDF に渡し、豚のフラット ファイルでさまざまな関数を呼び出すことです。
A = LOAD 'call_detail_records' USING org.apache.hcatalog.pig.HCatLoader();
DESCRIBE A;
REGISTER ZPigUdfs.jar;
DEFINE DFormat com.zna.pig.udf.DataColumnFormatter(A);
B = FOREACH A GENERATE DFormat($0);
DUMP B;
しかし、どうすればスキーマを渡すことができますか? DUMP A は実際にはテーブル全体をダンプしますが、メタデータのみが必要です。私の現在のUDF疑似コードは次のようになります
public class DataColumnFormatter extends EvalFunc {
private Tuple schema;
public DataColumnFormatter(Tuple schema) {
this.schema = schema;
}
@Override
public String exec(Tuple inputTuple) throws IOException {
if (inputTuple != null && inputTuple.size() > 0) {
String inpString = inputTuple.get(0).toString();
System.out.println(inpString);
System.out.println(schema);
/**
* Logic for splitting the string as pipe and apply functions based
* on positions of schema if(schema[1] -> date ){
*
* formatDate(input) }else if(schema[1] -> INT ){
*
* formatInt(input); }
*
*/
}
return null;
}
}
PIG UDF でスキーマを取得するにはどうすればよいですか、またはこれを実現する別の方法はありますか。
前もって感謝します。