Hive UDF:Runtime Exception内部错误:找不到未知的ObjectInspector



我尝试创建一个蜂巢UDF,该蜂巢返回多个结果。经度和纬度是UDF的参数。

运行该功能时,我会感到"失败:Runtime Exception内部错误:找不到未知的ObjectInspector"错误。

代码:

import java.util.ArrayList;
import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException;
import org.apache.hadoop.hive.ql.metadata.HiveException;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDF;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;

public class GetStateName extends GenericUDF {
    private ArrayList<String> result;
    public Object evaluate(DeferredObject[] arg0) throws HiveException {
        String lat = arg0[0].toString();
        String lng = arg0[1].toString();
        ArrayList<String> tmpLatLng = LookUp.getLatLng(lat,lng);
        result = new ArrayList<String>();
        result.add(tmpLatLng.get(0));
        result.add(tmpLatLng.get(1));
        return result;
    }
    public String getDisplayString(String[] arg0) {
        return new String("Address");
    }

    public ObjectInspector initialize(ObjectInspector[] arguments)
            throws UDFArgumentException {
        // Exactly one input argument
        if( arguments.length != 2 ) {
            throw new UDFArgumentLengthException( " accepts exactly two argument.");
        }
        return ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.javaHiveVarcharObjectInspector);
    }
}

hive udf不支持对象作为返回类型,用字符串替换对象公共对象评估 - &GT;公共字符串评估

相关内容

最新更新