@Test public void testExecWithEmptyDataBag() throws Exception { TupleFactory tupleFactory = TupleFactory.getInstance(); BagFactory bagFactory = BagFactory.getInstance(); DataBag resultBag = udf.exec(tupleFactory.newTuple(bagFactory.newDefaultBag())); assertNotNull(resultBag); assertEquals(0, resultBag.size()); }
@Override public DataBag exec(Tuple tuple) throws IOException { if (tuple == null || tuple.size() != 1) { throw new IOException("UDF StringListToListWithIndexes takes one argument: a list of strings"); } DataBag stringBag = (DataBag) tuple.get(0); BagFactory bagFactory = BagFactory.getInstance(); DataBag indexedBag = bagFactory.newDefaultBag(); if (stringBag == null) { return indexedBag; } TupleFactory tupleFactory = TupleFactory.getInstance(); int i = 0; for (Tuple stringTuple : stringBag) { Tuple indexedTuple = tupleFactory.newTuple(Lists.newArrayList(i++, stringTuple.get(0))); indexedBag.add(indexedTuple); } return indexedBag; }
StringListToListWithIndexes extends EvalFunc<DataBag> { @Override public DataBag exec(Tuple tuple) throws IOException { if (tuple == null || tuple.size() != 1) { throw new IOException("UDF StringListToListWithIndexes takes one argument: a list of strings"); } DataBag stringBag = (DataBag) tuple.get(0); BagFactory bagFactory = BagFactory.getInstance(); DataBag indexedBag = bagFactory.newDefaultBag(); if (stringBag == null) { return indexedBag; } TupleFactory tupleFactory = TupleFactory.getInstance(); int i = 0; for (Tuple stringTuple : stringBag) { Tuple indexedTuple = tupleFactory.newTuple(Lists.newArrayList(i++, stringTuple.get(0))); indexedBag.add(indexedTuple); } return indexedBag; } }
StringListToListWithIndexes extends EvalFunc<DataBag> { @Override public DataBag exec(Tuple tuple) throws IOException { if (tuple == null || tuple.size() != 1) { throw new IOException("UDF StringListToListWithIndexes takes one argument: a list of strings"); } DataBag stringBag = (DataBag) tuple.get(0); BagFactory bagFactory = BagFactory.getInstance(); DataBag indexedBag = bagFactory.newDefaultBag(); if (stringBag == null) { return indexedBag; } TupleFactory tupleFactory = TupleFactory.getInstance(); int i = 0; for (Tuple stringTuple : stringBag) { Tuple indexedTuple = tupleFactory.newTuple(Lists.newArrayList(i++, stringTuple.get(0))); indexedBag.add(indexedTuple); } return indexedBag; }  }
StringListToListWithIndexes extends EvalFunc<DataBag> { @Override public DataBag exec(Tuple tuple) throws IOException { if (tuple == null || tuple.size() != 1) { throw new IOException("UDF StringListToListWithIndexes takes one argument: a list of strings"); } DataBag stringBag = (DataBag) tuple.get(0); BagFactory bagFactory = BagFactory.getInstance(); DataBag indexedBag = bagFactory.newDefaultBag(); if (stringBag == null) { return indexedBag; } TupleFactory tupleFactory = TupleFactory.getInstance(); int i = 0; for (Tuple stringTuple : stringBag) { Tuple indexedTuple = tupleFactory.newTuple(Lists.newArrayList(i++, stringTuple.get(0))); indexedBag.add(indexedTuple); } return indexedBag; }  @Override DataBag exec(Tuple tuple); @Override Schema outputSchema(Schema input); }
StringListToListWithIndexes extends EvalFunc<DataBag> { @Override public DataBag exec(Tuple tuple) throws IOException { if (tuple == null || tuple.size() != 1) { throw new IOException("UDF StringListToListWithIndexes takes one argument: a list of strings"); } DataBag stringBag = (DataBag) tuple.get(0); BagFactory bagFactory = BagFactory.getInstance(); DataBag indexedBag = bagFactory.newDefaultBag(); if (stringBag == null) { return indexedBag; } TupleFactory tupleFactory = TupleFactory.getInstance(); int i = 0; for (Tuple stringTuple : stringBag) { Tuple indexedTuple = tupleFactory.newTuple(Lists.newArrayList(i++, stringTuple.get(0))); indexedBag.add(indexedTuple); } return indexedBag; }  @Override DataBag exec(Tuple tuple); @Override Schema outputSchema(Schema input);  }