首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过shell脚本执行hive udf

通过shell脚本执行hive udf
EN

Stack Overflow用户
提问于 2016-05-13 11:31:35
回答 2查看 794关注 0票数 0

我有一个Hive,它在蜂箱终端中工作得很好,我想通过shell脚本执行它。在蜂窝终端上,我能够执行以下命令:

代码语言:javascript
复制
use mashery_db;
add jar hdfs://nameservice1/tmp/nextdata_aggregations/custom_jar/readerCheck.jar;
add file hdfs://nameservice1/tmp/GeoLite2-City.mmdb;
CREATE TEMPORARY FUNCTION geoip AS 'com.mashery.nextdata.hive.udf.GeoIPGenericUDF';

但是当我在shell脚本中添加上面的代码时

代码语言:javascript
复制
hive -e "use mashery_db;"
hive -e "add jar hdfs://nameservice1/tmp/nextdata_aggregations/custom_jar/readerCheck.jar;"
hive -e "add file hdfs://nameservice1/tmp/GeoLite2-City.mmdb;"
hive -e "CREATE TEMPORARY FUNCTION geoip AS 'com.mashery.nextdata.hive.udf.GeoIPGenericUDF';"

第一个‘蜂巢-e’运行良好,并添加了jar,但最后一个创建临时函数不起作用。我正在犯以下错误:

代码语言:javascript
复制
FAILED: ParseException line 1:35 mismatched input 'com' expecting StringLiteral near 'AS' in create function statement

我也尝试过单引号。

代码语言:javascript
复制
hive -e "CREATE TEMPORARY FUNCTION geoip AS 'com.mashery.nextdata.hive.udf.GeoIPGenericUDF';"

那我就得到了FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.FunctionTask

代码语言:javascript
复制
FAILED: Class com.mashery.nextdata.hive.udf.GeoIPGenericUDF not found

hive是否支持shell脚本,如果它做错了什么,我正在做什么。提前感谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-05-17 22:03:03

每次对hive -e的调用都会产生一个新的进程,其中包含一个新的蜂巢外壳,它没有对上一个进程的记忆,所以蜂窝“忘记”了UDF所在的位置.一种解决方案是将它们链接在一个命令中,但是最好将所有的单元格命令放在一个文件中(例如"commands.hql"),使用hive -f commands.hql而不是-e

文件将如下所示:

代码语言:javascript
复制
use mashery_db;
add jar hdfs://nameservice1/tmp/nextdata_aggregations/custom_jar/readerCheck.jar;
add file hdfs://nameservice1/tmp/GeoLite2-City.mmdb;
CREATE TEMPORARY FUNCTION geoip AS 'com.mashery.nextdata.hive.udf.GeoIPGenericUDF';"
票数 1
EN

Stack Overflow用户

发布于 2016-05-18 18:58:46

您可以让它同时与hive -ehive -f一起工作。

代码语言:javascript
复制
hive -e "use mashery_db;
add jar hdfs://nameservice1/tmp/nextdata_aggregations/custom_jar/readerCheck.jar;
add file hdfs://nameservice1/tmp/GeoLite2-City.mmdb;
CREATE TEMPORARY FUNCTION geoip AS 'com.mashery.nextdata.hive.udf.GeoIPGenericUDF';"

将它们创建为一个文件并使用hive -f hive_file.hql也同样有效。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37208980

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档