ToTimeStamp extends UDF { public Timestamp evaluate(String s) { if (Strings.isNullOrEmpty(s)) { return null; } try { formatter.parse(s); return Timestamp.valueOf(s); } catch (Exception e) { LOG.warn(EVALUATE_IGNORE_MESSAGE); return null; } } ToTimeStamp(Map<String, String> config); Timestamp evaluate(String s);  }
@Test public void testEvaluate() { ToTimeStamp udf = new ToTimeStamp(null); String s1 = "2014-09-25 17:07:00"; assertNotNull(udf.evaluate(s1)); String s2 = "2014-09-25 17:07:00.056"; assertNotNull(udf.evaluate(s2)); String s3 = "abc"; assertNull(udf.evaluate(s3)); String s4 = "2014-09-25 17:07:00.56"; assertNotNull(udf.evaluate(s4)); String s5 = "2014-09-25 17:07:00.9999999"; assertNotNull(udf.evaluate(s5)); String s7 = "2014-09-25 17:07:00.9999999999"; assertNull(udf.evaluate(s7)); String s6 = "2014-09-25 17:07:00.999999"; assertNotNull(udf.evaluate(s6)); SimpleDateFormat formatter = new SimpleDateFormat(UDFConstants.TIMESTAMP_MSTIME_FORMAT); formatter.setLenient(false); System.out.println(formatter.format(udf.evaluate("2014-09-25 17:07:00.9"))); System.out.println(formatter.format(udf.evaluate("2014-09-25 17:07:00.999999999"))); s1 = "2014-9-9 7:7:5"; assertNotNull(udf.evaluate(s1)); s1 = "2014-9-9 7:7:5.9"; assertNotNull(udf.evaluate(s1)); }