@Test public void testEvaluate() { Month udf = new Month(null); assertTrue(udf.evaluate("2013-10-17 09:58:00") == TestUDFCommon.I_10); assertTrue(udf.evaluate("2013-00-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.DATE_FORMAT); calendar = Calendar.getInstance(); formatter1.setLenient(false); formatter2.setLenient(false); } try { Date date = null; if (dateString.length() > UDFConstants.DATE_FORMAT.length()) { date = formatter1.parse(dateString); } else { date = formatter2.parse(dateString); } calendar.setTime(date); return 1 + calendar.get(Calendar.MONTH); } catch (ParseException e) { LOG.warn(EVALUATE_IGNORE_MESSAGE); return null; } }
Month 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.DATE_FORMAT); calendar = Calendar.getInstance(); formatter1.setLenient(false); formatter2.setLenient(false); } try { Date date = null; if (dateString.length() > UDFConstants.DATE_FORMAT.length()) { date = formatter1.parse(dateString); } else { date = formatter2.parse(dateString); } calendar.setTime(date); return 1 + calendar.get(Calendar.MONTH); } catch (ParseException e) { LOG.warn(EVALUATE_IGNORE_MESSAGE); return null; } } }
Month 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.DATE_FORMAT); calendar = Calendar.getInstance(); formatter1.setLenient(false); formatter2.setLenient(false); } try { Date date = null; if (dateString.length() > UDFConstants.DATE_FORMAT.length()) { date = formatter1.parse(dateString); } else { date = formatter2.parse(dateString); } calendar.setTime(date); return 1 + calendar.get(Calendar.MONTH); } catch (ParseException e) { LOG.warn(EVALUATE_IGNORE_MESSAGE); return null; } } Month(Map<String, String> config); }
Month 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.DATE_FORMAT); calendar = Calendar.getInstance(); formatter1.setLenient(false); formatter2.setLenient(false); } try { Date date = null; if (dateString.length() > UDFConstants.DATE_FORMAT.length()) { date = formatter1.parse(dateString); } else { date = formatter2.parse(dateString); } calendar.setTime(date); return 1 + calendar.get(Calendar.MONTH); } catch (ParseException e) { LOG.warn(EVALUATE_IGNORE_MESSAGE); return null; } } Month(Map<String, String> config); Integer evaluate(String dateString); }
Month 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.DATE_FORMAT); calendar = Calendar.getInstance(); formatter1.setLenient(false); formatter2.setLenient(false); } try { Date date = null; if (dateString.length() > UDFConstants.DATE_FORMAT.length()) { date = formatter1.parse(dateString); } else { date = formatter2.parse(dateString); } calendar.setTime(date); return 1 + calendar.get(Calendar.MONTH); } catch (ParseException e) { LOG.warn(EVALUATE_IGNORE_MESSAGE); return null; } } Month(Map<String, String> config); Integer evaluate(String dateString);  }