Note that there are some explanatory texts on larger screens.

plurals
  1. POPig UDF for iso to yyyy-mm-dd hh:mm:ss.000
    text
    copied!<p>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. </p> <p>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.</p> <p><strong>Current data format: 2013-08-22T13:23:18.226220+01:00</strong></p> <p><strong>Required Data format: 2013-08-22 13:23:18.226</strong> </p> <pre><code>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&lt;String&gt;{ 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(); } } </code></pre> <p>How can i deal with the date conversions in pig?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload