Hive:python UDF 在关闭操作符时给出“Hive 运行时错误”
Posted
技术标签:
【中文标题】Hive:python UDF 在关闭操作符时给出“Hive 运行时错误”【英文标题】:Hive: python UDF gives “Hive Runtime Error while closing operators” 【发布时间】:2016-12-02 06:38:42 【问题描述】:我需要转换一些日期格式并根据某些业务逻辑操作为布尔条件。
但是,我在从 Hive 调用 python 脚本时遇到了问题。以下是我为转换示例 1 列的日期格式而编写的脚本:
import sys
def getYearMonthFromStringDate(dt):
year=0
month=0
try:
ss=dt.split('-')
year=ss[0]
month=ss[1]
except ValueError:
print "Error parsing date string %s" %dt
return int(year)*100+int(month)
for line in sys.stdin:
tempArr=line.split('\t')
accountgl0s=tempArr[0]
agl0 = getYearMonthFromStringDate(accountgl0s)
output_list = [accountgl0s, ag10]
print '\t'.join(output_list)
我使用以下命令将文件添加到分布式缓存中:
add file /folder/date.py
现在,我使用 Transform 在我的 hive 表的 col accountgl0s
上调用这个 Python 函数,如下所示:
Input column accountgl0s = '2016-10-01'
select transform(accountgl0) using 'python date.py' as (accountgl0s,agl0) from sample;
我的预期输出应该是2016-10-01 201610
。但我收到以下错误:
Error: java.lang.RuntimeException: Hive Runtime Error while closing operators
at org.apache.hadoop.hive.ql.exec.mr.ExecMapper.close(ExecMapper.java:217)
at org.apache.hadoop.mapred.MapRunner.run(MapRunner.java:61)
at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:453)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:343)
at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:163)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:422)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1671)
at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)
Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: [Error 20003]: An error occurred when trying to close the Operator running your custom script.
at org.apache.hadoop.hive.ql.exec.ScriptOperator.close(ScriptOperator.java:557)
at org.apache.hadoop.hive.ql.exec.Operator.close(Operator.java:610)
at org.apache.hadoop.hive.ql.exec.Operator.close(Operator.java:610)
at org.apache.hadoop.hive.ql.exec.Operator.close(Operator.java:610)
at org.apache.hadoop.hive.ql.exec.mr.ExecMapper.close(ExecMapper.java:199)
... 8 more
FAILED: Execution Error, return code 20003 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask. An error occurred when trying to close the Operator running your custom script.
MapReduce Jobs Launched:
Stage-Stage-1: Map: 1 HDFS Read: 0 HDFS Write: 0 FAIL
Total MapReduce CPU Time Spent: 0 msec
【问题讨论】:
在这些错误信息的上方,输出信息中有一个URL,如Starting Job = job_1480642810315_083110, Tracking URL = hadoop-test15.int.xxxxxx.com:8088/proxy/…,访问这个url可以找到python错误信息的相关信息。 为什么要编写自定义python脚本来拆分字符串? 【参考方案1】:当您想计算数字时,您必须将变量类型更改为浮动:
f_accountgl0s = float(accountgl0s)
【讨论】:
以上是关于Hive:python UDF 在关闭操作符时给出“Hive 运行时错误”的主要内容,如果未能解决你的问题,请参考以下文章
Hive 给出 SemanticException [错误 10014]:运行我的 UDF 时