ToString extends UDF { public String evaluate(Object s) { if (s == null) { return null; } try { StreamingDataType dataType = StreamingDataType.getDataType(s.getClass()); return dataType.toStringValue(s); } catch (StreamingException e) { LOG.warn(EVALUATE_IGNORE_MESSAGE); return null; } } ToString(Map<String, String> config); String evaluate(Object s);  }
@Test public void testEvaluate() { ToString udf = new ToString(null); ToTimeStamp toTimeStamp = new ToTimeStamp(null); ToDate toDate = new ToDate(null); ToTime toTime = new ToTime(null); assertEquals(udf.evaluate(true), "true"); assertEquals(udf.evaluate(false), "false"); assertEquals(udf.evaluate(null), null); assertEquals(udf.evaluate(1), "1"); assertEquals(udf.evaluate(1L), "1"); assertEquals(udf.evaluate(1.0F), "1.0"); assertEquals(udf.evaluate(1.0D), "1.0"); assertEquals(udf.evaluate(new BigDecimal("1.0")), "1.0"); assertEquals(udf.evaluate(toTime.evaluate("15:40:00")), "15:40:00"); assertEquals(udf.evaluate(toDate.evaluate("2013-10-17")), "2013-10-17"); assertEquals(udf.evaluate(toDate.evaluate("2013-1-17")), "2013-01-17"); assertTrue(udf.evaluate(toTimeStamp.evaluate("2013-10-17 15:40:00.000000")).equals("2013-10-17 15:40:00.000")); assertTrue(udf.evaluate(toTimeStamp.evaluate("2013-10-17 15:40:00")).equals("2013-10-17 15:40:00.000")); assertFalse(udf.evaluate(true).equals("True")); assertFalse(udf.evaluate(false).equals("False")); }