I want to convert the ISO time format to yyyy-mm-dd hh: mm: ss.SSS. However, Im is not able to achieve conversion. I am new to pig and am trying to write udf to handle the conversion from ISO format to yyyy-mm-dd hh: mm: ss.SSS.
I ask you, I tried the built-in functions of the pig (FORMAT, DATE_FORMAT), but I could not convert the data to the required 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(); } }
How can I handle date conversion in a pig?
source share