我尝试创建一个配置单元 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);
}
}