@Test public void testEvaluate() { Second udf = new Second(null); assertTrue(udf.evaluate("2013-10-17 09:58:00.111") == 0); assertTrue(udf.evaluate("2013-10-17 09:58:00") == 0); assertTrue(udf.evaluate("09:58:00") == 0); assertTrue(udf.evaluate("24:58:60") == null); assertTrue(udf.evaluate("00:58:00") == 0); assertTrue(udf.evaluate("00:00:00") == 0); assertTrue(udf.evaluate("23:59:59") == 59); assertTrue(udf.evaluate("24:00:00") == null); assertTrue(udf.evaluate("2013-10-17") == null); }
public Integer evaluate(String dateString) { if (dateString == null) { return null; } if (formatter1 == null) { formatter1 = new SimpleDateFormat(UDFConstants.TIMESTAMP_FORMAT); formatter2 = new SimpleDateFormat(UDFConstants.TIME_FORMAT); calendar = Calendar.getInstance(); formatter1.setLenient(false); formatter2.setLenient(false); } try { Date date = null; if (dateString.length() > UDFConstants.TIME_FORMAT.length()) { date = formatter1.parse(dateString); } else { date = formatter2.parse(dateString); } calendar.setTime(date); return calendar.get(Calendar.SECOND); } catch (ParseException e) { LOG.warn(EVALUATE_IGNORE_MESSAGE); return null; } }
Second extends UDF { public Integer evaluate(String dateString) { if (dateString == null) { return null; } if (formatter1 == null) { formatter1 = new SimpleDateFormat(UDFConstants.TIMESTAMP_FORMAT); formatter2 = new SimpleDateFormat(UDFConstants.TIME_FORMAT); calendar = Calendar.getInstance(); formatter1.setLenient(false); formatter2.setLenient(false); } try { Date date = null; if (dateString.length() > UDFConstants.TIME_FORMAT.length()) { date = formatter1.parse(dateString); } else { date = formatter2.parse(dateString); } calendar.setTime(date); return calendar.get(Calendar.SECOND); } catch (ParseException e) { LOG.warn(EVALUATE_IGNORE_MESSAGE); return null; } } }
Second extends UDF { public Integer evaluate(String dateString) { if (dateString == null) { return null; } if (formatter1 == null) { formatter1 = new SimpleDateFormat(UDFConstants.TIMESTAMP_FORMAT); formatter2 = new SimpleDateFormat(UDFConstants.TIME_FORMAT); calendar = Calendar.getInstance(); formatter1.setLenient(false); formatter2.setLenient(false); } try { Date date = null; if (dateString.length() > UDFConstants.TIME_FORMAT.length()) { date = formatter1.parse(dateString); } else { date = formatter2.parse(dateString); } calendar.setTime(date); return calendar.get(Calendar.SECOND); } catch (ParseException e) { LOG.warn(EVALUATE_IGNORE_MESSAGE); return null; } } Second(Map<String, String> config); }
Second extends UDF { public Integer evaluate(String dateString) { if (dateString == null) { return null; } if (formatter1 == null) { formatter1 = new SimpleDateFormat(UDFConstants.TIMESTAMP_FORMAT); formatter2 = new SimpleDateFormat(UDFConstants.TIME_FORMAT); calendar = Calendar.getInstance(); formatter1.setLenient(false); formatter2.setLenient(false); } try { Date date = null; if (dateString.length() > UDFConstants.TIME_FORMAT.length()) { date = formatter1.parse(dateString); } else { date = formatter2.parse(dateString); } calendar.setTime(date); return calendar.get(Calendar.SECOND); } catch (ParseException e) { LOG.warn(EVALUATE_IGNORE_MESSAGE); return null; } } Second(Map<String, String> config); Integer evaluate(String dateString); }
Second extends UDF { public Integer evaluate(String dateString) { if (dateString == null) { return null; } if (formatter1 == null) { formatter1 = new SimpleDateFormat(UDFConstants.TIMESTAMP_FORMAT); formatter2 = new SimpleDateFormat(UDFConstants.TIME_FORMAT); calendar = Calendar.getInstance(); formatter1.setLenient(false); formatter2.setLenient(false); } try { Date date = null; if (dateString.length() > UDFConstants.TIME_FORMAT.length()) { date = formatter1.parse(dateString); } else { date = formatter2.parse(dateString); } calendar.setTime(date); return calendar.get(Calendar.SECOND); } catch (ParseException e) { LOG.warn(EVALUATE_IGNORE_MESSAGE); return null; } } Second(Map<String, String> config); Integer evaluate(String dateString);  }