Hier UDF-Code istPig Java UDF Ausgabe
package myudf;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.pig.EvalFunc;
import org.apache.pig.data.Tuple;
public class DateFormat extends EvalFunc<String> {
public String exec(Tuple input) throws IOException {
if (input == null || input.size() == 0) {
return null;
}
try {
String dateStr = (String)input.get(0);
SimpleDateFormat readFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss.SSS aa");
SimpleDateFormat writeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
Date date = null;
try {
date = readFormat.parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
}
return writeFormat.format(date).toString();
} catch(Exception e) {
throw new IOException("Caught exception processing input row ", e);
}
}
}
ein Glas dieses Exportiert und in Grunzen registriert
Register /local/path/to/UDFDate.jar;
A = LOAD 'hdfs date file';
B = FOREACH A GENERATE UDFDate.myudf.DateFormat($0);
Gibt Fehler
[main] ERROR org.apache. pig.tools.grunt.Grunt - FEHLER 1070: Konnte nicht UDFDate.DateFormat mithilfe von Imports auflösen: [, java.lang., org.apache.pig.builtin., org.apache.pig.impl.builtin.]
was MyUDF ist. Haben Sie Java-Datei myudf in Ihrem Paket UDFDate? –
Was ist die erste Zeile in 'DateFormat.java' Datei? –
Sorry Jungs .. Ich verpasste den Paketnamen .. – TKHN