String
我已经以格式存储了用户代理字符串。
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36
我想从用户代理字符串中提取浏览器。所以我使用了ua-parser-java库。
Hive UDF 代码如下:
public class BrowserInfo extends UDF{
public Text evaluate(Text input) {
if(input == null) return null;
String uaString = input.toString();
Parser uaParser= null;
try
{
uaParser = new Parser();
}
catch (IOException e)
{
e.printStackTrace();
}
Client c = uaParser.parse(uaString);
return new Text(c.userAgent.family);
}
}
它给了我以下例外。
Failed with exception java.io.IOException:org.apache.hadoop.hive.ql.metadata.HiveException: Unable to execute method public org.apache.hadoop.io.Text dhruv.udf.BrowserInfo.evaluate(org.apache.hadoop.io.Text)
on object dhruv.udf.BrowserInfo@5379d8 of class dhruv.udf.BrowserInfo
with arguments {"Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)":org.apache.hadoop.io.Text} of size 1
尝试使用String
而不是Text
但得到相同的异常。如果没有配置单元,此代码可以完美运行。更新:hadoop 或 hive 的日志中没有关于此的详细信息。