ArrayProcessUDTF

package com.suning.udf;


import org.apache.hadoop.hive.ql.metadata.HiveException;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDTF;

public class ArrayProcessUDTF extends GenericUDTF {

    @Override
    public void process(Object[] args) throws HiveException {

        String input = args[0].toString();
        String[] test = input.split(",");
        for (int i = 0; i < test.length; i++) {
            try {
                String[] result = (test[i] + ":" + String.valueOf(i + 1)).split(":");
                forward(result);
            } catch (Exception e) {
                continue;
            }
        }
    }

    @Override
    public void close() throws HiveException {

    }
}    // select array_process('a,c,b')    
//返回元素和索引 a 1 c 2 b 3
原文地址:https://www.cnblogs.com/yin-fei/p/10879710.html