Products | Versions |
---|---|
TIBCO Streaming | - |
What code is needed to return a list of tuples in a Custom Java Function using the StreamBase Client API?
public class TheClass { private static Schema OutputSchema = null;2. Create a custom function resolver that defines the schema (example)
public static CompleteDataType CombineWithListCustomFunctionResolver0( CompleteDataType arg0, CompleteDataType arg1, CompleteDataType arg2) { ArrayList<Schema.Field> Fields = new ArrayList<Schema.Field>(); Fields.add(Schema.createListField("theList",CompleteDataType.forString())); Fields.add(Schema.createField(DataType.DOUBLE, "theDouble")); Fields.add(Schema.createField(DataType.INT, "theInt")); OutputSchema = new Schema(null,Fields); return CompleteDataType.forList(CompleteDataType.forTuple(OutputSchema)); }Note that this doesn't show the input value typechecking logic.
@CustomFunctionResolver("CombineWithListCustomFunctionResolver0") public static List<?> CombineWithList(List<String> arg0, Double arg1, Integer arg2) { Tuple dataTuple = OutputSchema.createTuple(); // create the tuple ArrayList<Tuple> dataList = new ArrayList<Tuple>(); // create the list to be emitted try { // load the tuple dataTuple.setList(0, arg0); dataTuple.setDouble(1, arg1); dataTuple.setInt(2, arg2); } catch (NullValueException e) { e.printStackTrace(); } catch (TupleException e) { e.printStackTrace(); } dataList.add(dataTuple); // add the tuple to the list, repeat as necessary with different values return dataList; }