配置单元udf:runtimeexception内部错误:找不到未知的objectinspector

iih3973s  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(730)

我尝试创建一个hiveudf,它返回多个结果。经度和纬度是udf的参数。
运行该函数时,出现“failed:runtimeexception internal error:cannot find objectinspector for unknown”错误。
代码:

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);
    }

}
enxuqcxy

enxuqcxy1#

配置单元自定义项不支持对象作为返回类型,请用字符串替换对象。public object evaluate->public string evaluate

相关问题