【发布时间】:2012-10-11 18:55:13
【问题描述】:
我正在编写一个自定义 Hive UDF,以根据属性文件中定义的值解析 Map 中的键/值对。格式为 validate(Map
我遇到的问题是 GenericUDF 类似乎期望这两个值对于查询都是动态的,因为 initialize() 函数将参数转换为 ObjectInspectors,从事物的外观来看,这没有可能的选项返回他们正在检查的对象。
我希望初始化函数加载属性文件,并且评估函数返回通过/失败。这几乎不足以涵盖我尝试过的所有内容,但希望它能让知道他们在做什么的人对这个问题有一个好主意:
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
mapOI = (MapObjectInspector) arguments[0];
StringObjectInspector stringOI = (StringObjectInspector) arguments[1];
try {
// Begin Debug
System.out.println(stringOI.getPrimitiveJavaObject(((DeferredObject) arguments[1]).get()));
// End Debug
loadProperties(stringOI.getPrimitiveJavaObject(((DeferredObject) arguments[1]).get()));
}
catch (HiveException exception) {
throw new UDFArgumentTypeException(1, "Failed to cast properties file path for evaluation by loadProperties... What did you do?");
}
【问题讨论】:
-
你想返回什么?stringOI还是mapOI?
-
抱歉,代码不够详细,但我希望将 stringOI 引用的字符串传递给另一个函数。在我开发的这一点上,我试图将其转换为评估函数用于检索 Ojbect 的 DeferredObject,并捕获 HiveException 并重新抛出为 UDFArgumentException 以吃掉编译错误。编辑传入。
标签: java hive user-defined-functions