### Question:
HiveGenericUDTF extends TableFunction<Row> implements HiveFunction { public void eval(Object... args) throws HiveException { if (isArgsSingleArray) { args = new Object[] {args}; } checkArgument(args.length == conversions.length); if (!allIdentityConverter) { for (int i = 0; i < args.length; i++) { args[i] = conversions[i].toHiveObject(args[i]); } } function.process(args); } HiveGenericUDTF(HiveFunctionWrapper<GenericUDTF> hiveFunctionWrapper); @Override void open(FunctionContext context); void eval(Object... args); @Override void setArgumentTypesAndConstants(Object[] constantArguments, DataType[] argTypes); @Override DataType getHiveResultType(Object[] constantArguments, DataType[] argTypes); @Override TypeInformation getResultType(); @Override void close();  }### Answer:
@Test public void testOverSumInt() throws Exception { Object[] constantArgs = new Object[] { null, 4 }; DataType[] dataTypes = new DataType[] { DataTypes.INT(), DataTypes.INT() }; HiveGenericUDTF udf = init( TestOverSumIntUDTF.class, constantArgs, dataTypes ); udf.eval(5, 4); assertEquals(Arrays.asList(Row.of(9), Row.of(9)), collector.result); constantArgs = new Object[] {}; dataTypes = new DataType[] {}; udf = init( TestOverSumIntUDTF.class, constantArgs, dataTypes ); udf.eval(); assertEquals(Arrays.asList(), collector.result); }
@Test public void testSplit() throws Exception { Object[] constantArgs = new Object[] { null }; DataType[] dataTypes = new DataType[] { DataTypes.STRING() }; HiveGenericUDTF udf = init( TestSplitUDTF.class, constantArgs, dataTypes ); udf.eval("1,2,3,5"); assertEquals(Arrays.asList(Row.of("1"), Row.of("2"), Row.of("3"), Row.of("5")), collector.result); }
@Test public void testStack() throws Exception { Object[] constantArgs = new Object[] { 2, null, null, null, null }; DataType[] dataTypes = new DataType[] { DataTypes.INT(), DataTypes.STRING(), DataTypes.STRING(), DataTypes.STRING(), DataTypes.STRING() }; HiveGenericUDTF udf = init( GenericUDTFStack.class, constantArgs, dataTypes ); udf.eval(2, "a", "b", "c", "d"); assertEquals(Arrays.asList(Row.of("a", "b"), Row.of("c", "d")), collector.result); }
@Test public void testArray() throws Exception { Object[] constantArgs = new Object[] { null }; DataType[] dataTypes = new DataType[] { DataTypes.ARRAY(DataTypes.INT()) }; HiveGenericUDTF udf = init( GenericUDTFPosExplode.class, constantArgs, dataTypes ); udf.eval(new Integer[] { 1, 2, 3}); assertEquals(Arrays.asList(Row.of(0, 1), Row.of(1, 2), Row.of(2, 3)), collector.result); }
@Test public void testStruct() throws Exception { Object[] constantArgs = new Object[] { null }; DataType[] dataTypes = new DataType[] { DataTypes.ARRAY( DataTypes.ROW( DataTypes.FIELD("1", DataTypes.INT()), DataTypes.FIELD("2", DataTypes.DOUBLE()) ) ) }; HiveGenericUDTF udf = init( GenericUDTFInline.class, constantArgs, dataTypes ); udf.eval( new Row[]{ Row.of(1, 2.2d), Row.of(3, 4.4d) } ); assertEquals(Arrays.asList(Row.of(1, 2.2), Row.of(3, 4.4)), collector.result); }