Pig UDF for iso to yyyy-mm-dd hh:mm:ss.000
Iam looking to convert the ISO time format to yyyy-mm-dd hh:mm:ss.SSS.
However Im not able achive the conversion. Iam new to pig and im trying to
write a udf to handle the conversion from ISO format to yyyy-mm-dd
hh:mm:ss.SSS.
Kindly guide me I tried the built functions of pig (FORMAT,DATE_FORMAT)
however was not able to convert the data to the needed format.
Current data format 2013-08-22T13:23:18.226220+01:00
**Required Data format 2013-08-22 13:23:18.226**
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.pig.EvalFunc;
import org.apache.pig.data.Tuple;
import org.apache.pig.EvalFunc;
import org.joda.time.DateTime;
import org.joda.time.format.*;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.DateTimeFormatterBuilder;
public class test extends EvalFunc<String>{
public String exec(Tuple input) throws IOException {
if ((input == null) || (input.size() == 0))
return null;
try{
String time = (String)input.get(0);
DateFormat dt = new SimpleDateFormat ("yyyy-mm-dd hh:mm:ss.SSS");
Date d_t = dt.parse(time);
String timedt = getTimedt(d_t);
return timedt;
} catch (ParseException e) {
return null;
}
}
private String getTimedt(Date d_t) {
DateTimeFormatterBuilder formatter = new DateTimeFormatterBuilder();
}
}
Please provide some suggestions for dealing with the date conversions in pig
Thanks a lot ,
mini
No comments:
Post a Comment