-- 1. 说明
A custom UDTF can be created by extending the GenericUDTF abstract class andthen implementing the initialize, process,and possibly close methods. The initialize method is called by Hive to notify the UDTF the argument typesto expect. The UDTF must thenreturn an object inspector corresponding to the row objects that the UDTF will generate. Once initialize() has been called, Hive will give rowsto the UDTF using the process() method.Whilein process(), the UDTF can produce and forward rowsto other operators by calling forward(). Lastly, Hive will call the close() method whenall the rows have passed to the UDTF.-- 解析如上内容:1. 自定义UDTF函数,继承于抽象类GenericUDTF;2. 实现initialize, process,close 的三个方法;
3. 三个方法的作用说明:
1.'initialize()':
a、规定形参的参数类型:Hive调用initialize()方法,来告诉UDTF函数接收参数的类型,然后在这个方法中就可以对参数的
类型进行校验,参数类型包括个数、数据类型等等
b、规定函数返回结果数据类型:返回initialize()方法必须返回一个与UDTF将生成的行对象对应的对象检查器
2.'process()':
a、调用时机:initialize()被调用以后,即对输入的数据进行了检查满足条件以后,执行这个方法
b、作用:一行数据调用一次process方法,process方法的内部,会遍历这一行数据,如果是数组,那就遍历数组,遍历以后的
一个元素,调用一次forward()方法,对数据进行输出。
3.'close()':
a、调用时机:当hive中的所有行都通过了UDTF函数以后,则Hive会调用这个close方法
b、作用:关闭资源。