Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hive 配置单元UDF:运行时异常内部错误:找不到未知的ObjectInspector_Hive_Hive Udf - Fatal编程技术网

Hive 配置单元UDF:运行时异常内部错误:找不到未知的ObjectInspector

Hive 配置单元UDF:运行时异常内部错误:找不到未知的ObjectInspector,hive,hive-udf,Hive,Hive Udf,我尝试创建一个配置单元UDF,它返回多个结果。 经度和纬度是UDF的参数 运行该函数时,出现“失败:RuntimeException内部错误:找不到未知的ObjectInspector”错误 代码: import java.util.ArrayList; 导入org.apache.hadoop.hive.ql.exec.UDFArgumentException; 导入org.apache.hadoop.hive.ql.exec.udfargumentlengtheexception; 导入org

我尝试创建一个配置单元UDF,它返回多个结果。 经度和纬度是UDF的参数

运行该函数时,出现“失败:RuntimeException内部错误:找不到未知的ObjectInspector”错误

代码:

import java.util.ArrayList;
导入org.apache.hadoop.hive.ql.exec.UDFArgumentException;
导入org.apache.hadoop.hive.ql.exec.udfargumentlengtheexception;
导入org.apache.hadoop.hive.ql.metadata.HiveException;
导入org.apache.hadoop.hive.ql.udf.generic.GenericUDF;
导入org.apache.hadoop.hive.serde2.objectinspector.objectinspector;
导入org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
导入org.apache.hadoop.hive.serde2.objectinspector.primitive.primitive objectinspector工厂;
公共类GetStateName扩展了GenericUDF{
私有数组列表结果;
公共对象求值(延迟对象[]arg0)引发HiveException{
字符串lat=arg0[0]。toString();
字符串lng=arg0[1]。toString();
ArrayList tmpLatLng=LookUp.getLatLng(lat,lng);
结果=新的ArrayList();
result.add(tmpLatLng.get(0));
结果.add(tmpLatLng.get(1));
返回结果;
}
公共字符串getDisplayString(字符串[]arg0){
返回新字符串(“地址”);
}
公共ObjectInspector初始化(ObjectInspector[]参数)
抛出UDFArgumentException{
//只有一个输入参数
if(arguments.length!=2){
抛出新的udfargumentlengtheexception(“恰好接受两个参数”);
}
返回ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.javaHiveVarcharObjectInspector);
}
}

配置单元UDF不支持对象作为返回类型,请将对象替换为字符串
公共对象求值->公共字符串求值

配置单元自定义项不支持对象作为返回类型,请将对象替换为字符串
公共对象评估->公共字符串评估

请在您的答案中添加一些描述,并解释其工作原理和解决问题的方法。请在您的答案中添加一些描述,并解释其工作原理和解决问题的方法。
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);
    }

}