@Test public void testExec3() throws IOException { Tuple input = tupleFactory.newTuple(); Calendar cal = Calendar.getInstance(); cal.set(2011, Calendar.JANUARY, 23); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); String inputDateStr = sdf.format(cal.getTime()); input.append(inputDateStr); String outputDateStr = convDateFormat.exec(input); assertNotNull(outputDateStr); assertEquals(outputDateStr, "2011-01-23"); }
@Override public String exec(Tuple input) throws IOException { if (input == null || input.size() == 0) { return null; } if (inputSdf == null || outputSdf == null) { this.inputSdf = new SimpleDateFormat((String) input.get(1)); this.outputSdf = new SimpleDateFormat((String) input.get(2)); } String s = null; try { Date d = inputSdf.parse((String) input.get(0)); s = outputSdf.format(d); } catch (ParseException e) { pigLogger.warn(this, "Date parsing error", ERRORS.DateParseError); } return s; }
ConvertDateFormat extends EvalFunc<String> { @Override public String exec(Tuple input) throws IOException { if (input == null || input.size() == 0) { return null; } if (inputSdf == null || outputSdf == null) { this.inputSdf = new SimpleDateFormat((String) input.get(1)); this.outputSdf = new SimpleDateFormat((String) input.get(2)); } String s = null; try { Date d = inputSdf.parse((String) input.get(0)); s = outputSdf.format(d); } catch (ParseException e) { pigLogger.warn(this, "Date parsing error", ERRORS.DateParseError); } return s; } }
ConvertDateFormat extends EvalFunc<String> { @Override public String exec(Tuple input) throws IOException { if (input == null || input.size() == 0) { return null; } if (inputSdf == null || outputSdf == null) { this.inputSdf = new SimpleDateFormat((String) input.get(1)); this.outputSdf = new SimpleDateFormat((String) input.get(2)); } String s = null; try { Date d = inputSdf.parse((String) input.get(0)); s = outputSdf.format(d); } catch (ParseException e) { pigLogger.warn(this, "Date parsing error", ERRORS.DateParseError); } return s; } ConvertDateFormat();  ConvertDateFormat(final String inputDateFormat, final String outputDateFormat); }
ConvertDateFormat extends EvalFunc<String> { @Override public String exec(Tuple input) throws IOException { if (input == null || input.size() == 0) { return null; } if (inputSdf == null || outputSdf == null) { this.inputSdf = new SimpleDateFormat((String) input.get(1)); this.outputSdf = new SimpleDateFormat((String) input.get(2)); } String s = null; try { Date d = inputSdf.parse((String) input.get(0)); s = outputSdf.format(d); } catch (ParseException e) { pigLogger.warn(this, "Date parsing error", ERRORS.DateParseError); } return s; } ConvertDateFormat();  ConvertDateFormat(final String inputDateFormat, final String outputDateFormat); @Override String exec(Tuple input); }
ConvertDateFormat extends EvalFunc<String> { @Override public String exec(Tuple input) throws IOException { if (input == null || input.size() == 0) { return null; } if (inputSdf == null || outputSdf == null) { this.inputSdf = new SimpleDateFormat((String) input.get(1)); this.outputSdf = new SimpleDateFormat((String) input.get(2)); } String s = null; try { Date d = inputSdf.parse((String) input.get(0)); s = outputSdf.format(d); } catch (ParseException e) { pigLogger.warn(this, "Date parsing error", ERRORS.DateParseError); } return s; } ConvertDateFormat();  ConvertDateFormat(final String inputDateFormat, final String outputDateFormat); @Override String exec(Tuple input);  }