python写hive的UDF问题
我用python写UDF函数时总报错:python:importsysdefmain():forlineinsys.stdin:line=line.strip()fiel...
我用python写UDF函数时总报错:
python:
import sys
def main():
for line in sys.stdin:
line = line.strip()
fields = line.split('\t')
if fields[2] is None or fields[2]=""
fields[2] = "o"
print '%s\t%s\t%s' % (fields[0],fields[1],fields[2])
if __name__ == "__main__":
main()
hql语句:
select transform(device_id,device_type,gender) using 'python gender.py' as(device_id,device_type,gender) from dm_device_gender where year=2017 and month=02 and day=23 limit 20;
报错:
Error: java.lang.RuntimeException: org.apache.hadoop.hive.ql.metadata.HiveException: Hive Runtime Error while processing row {"device_id":"pom7vptz-wnu7-tvxj-xeqm-7anh1ga5vo9x","device_type":"gaid","package_names":"com.k12.equivalenceTiles","source":"m:dsp","gender":"f","ratio":"0.5002738483938325","tag":"calc","year":"2017","month":"02","day":"23"}
at org.apache.hadoop.hive.ql.exec.mr.ExecMapper.map(ExecMapper.java:195)
at org.apache.hadoop.mapred.MapRunner.run(MapRunner.java:54)
at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:455)
请问大神这是什么原因?
python改成这样就没事:
import sys
def main():
for line in sys.stdin:
line = line.strip()
fields = line.split('\t')
if fields[2] is None or fields[2]=""
fields[2] = "o"
try:
print '%s\t%s\t%s' % (fields[0],fields[1],fields[2])
except ValueError:
continue
if __name__ == "__main__":
main()
但是好像缺少数据。 展开
python:
import sys
def main():
for line in sys.stdin:
line = line.strip()
fields = line.split('\t')
if fields[2] is None or fields[2]=""
fields[2] = "o"
print '%s\t%s\t%s' % (fields[0],fields[1],fields[2])
if __name__ == "__main__":
main()
hql语句:
select transform(device_id,device_type,gender) using 'python gender.py' as(device_id,device_type,gender) from dm_device_gender where year=2017 and month=02 and day=23 limit 20;
报错:
Error: java.lang.RuntimeException: org.apache.hadoop.hive.ql.metadata.HiveException: Hive Runtime Error while processing row {"device_id":"pom7vptz-wnu7-tvxj-xeqm-7anh1ga5vo9x","device_type":"gaid","package_names":"com.k12.equivalenceTiles","source":"m:dsp","gender":"f","ratio":"0.5002738483938325","tag":"calc","year":"2017","month":"02","day":"23"}
at org.apache.hadoop.hive.ql.exec.mr.ExecMapper.map(ExecMapper.java:195)
at org.apache.hadoop.mapred.MapRunner.run(MapRunner.java:54)
at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:455)
请问大神这是什么原因?
python改成这样就没事:
import sys
def main():
for line in sys.stdin:
line = line.strip()
fields = line.split('\t')
if fields[2] is None or fields[2]=""
fields[2] = "o"
try:
print '%s\t%s\t%s' % (fields[0],fields[1],fields[2])
except ValueError:
continue
if __name__ == "__main__":
main()
但是好像缺少数据。 展开
3个回答
展开全部
我最近也在搞这个,不用try的话也是一直报错,用了try就直接没数据。我把数据打印出来,发现每一行后面多了一个NULL,找了几天也没找出来从哪来的
知道什么原因的话说一下,谢谢
知道什么原因的话说一下,谢谢
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
hive的jdbc包,jar包名字大概是hive-jdbc.jar,你找找hive包下带Jdbc的看看。
追问
这应该和jar包没问题,用的公司服务器上的jar包。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询