StringFirstNotEmpty extends EvalFunc<String> { @Override public String exec(Tuple input) throws IOException { if (input == null) { return null; } for (int i = 0; i < input.size(); i++) { String ret = (String) input.get(i); if (ret != null && !ret.isEmpty()) { return ret; } } return null; }  @Override String exec(Tuple input);  }
@Test public void testUDF() throws IOException { StringFirstNotEmpty udf = new StringFirstNotEmpty(); TupleFactory factory = TupleFactory.getInstance(); assertNull(udf.exec(null)); assertNull(udf.exec(factory.newTuple())); assertNull(udf.exec(factory.newTuple((String) null))); assertEquals("tup", udf.exec(factory.newTuple("tup"))); assertNull(udf.exec(factory.newTuple(Lists.newArrayList()))); assertNull(udf.exec(factory.newTuple(Lists.newArrayList(null, null)))); assertEquals("val1", udf.exec(factory.newTuple(Lists.newArrayList("val1", null, "256", "90")))); assertEquals("k256", udf.exec(factory.newTuple(Lists.newArrayList(null, null, null, "k256", "567")))); assertEquals("k256", udf.exec(factory.newTuple(Lists.newArrayList(null, "", null, "k256", "567")))); }