1

我尝试创建一个配置单元 UDF,它返回多个结果。经度和纬度是 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);
    }

}
4

1 回答 1

0

hive UDF 不支持 Object 作为返回类型,将 Object 替换为 String。 public Object evaluate -> public String evaluate

于 2020-07-09T07:58:42.333 回答