在Amazon EMR上運行Hive 0.11,我試圖用GenericUDF類創建一個簡單的UDF。我正在嘗試使用UDF,只需從列中獲取一個值,然後將其打印回屏幕。整個觀點是看看我能否在構建更復雜的東西之前完成這個工作。Hive GenericUDF錯誤 - RuntimeException typeInfo不能爲空
我編譯jar,加載到配置單元中,並創建一個臨時函數。
add jar ..../GenericTest.jar;
create temporary function gen_test as 'GenericTest';
當我運行數錯誤的參數的函數,我得到了預期的錯誤:
SemanticException [Error 10015]: Line 1:13 Arguments length mismatch 'gen_test': Wrong # of Args
然而,當我通過它的參數的權數,這與消息立即失敗:
FAILED: RuntimeException typeInfo cannot be null!
我到目前爲止一直無法找到這個問題的根源。下面是這個UDF的代碼。
import org.apache.hadoop.hive.ql.exec.Description;
import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException;
import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
import org.apache.hadoop.hive.ql.metadata.HiveException;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDF;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDFUtils;
import org.apache.hadoop.hive.serde2. objectinspector.ObjectInspector;
public class GenericTest extends GenericUDF {
private GenericUDFUtils.ReturnObjectInspectorResolver returnOIResolver;
private ObjectInspector[] argumentOIs;
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
argumentOIs = arguments;
if (arguments.length != 1) {
throw new UDFArgumentLengthException("Wrong # of Args");
}
if (arguments[0].getCategory() != ObjectInspector.Category.PRIMITIVE)
throw new UDFArgumentTypeException(0, "Only primitive type arguments are accepted");
returnOIResolver = new GenericUDFUtils.ReturnObjectInspectorResolver(true);
return returnOIResolver.get();
}
public Object evaluate(DeferredObject[] arguments) throws HiveException {
Object retVal = returnOIResolver.convertIfNecessary(arguments[0].get(), argumentOIs[0]);
return retVal;
}
public String getDisplayString(String[] children){
String rt = "get Display String test";
return rt;
}
}
我已經得到這個運行。在initialize()中,我需要類似'returnOIResolver.update(arguments [0]);'以便返回returnOIResolver.get();'將返回一些東西(ObjectInspector作爲返回值)。 – DJElbow 2014-09-19 19:15:29