通过shell脚本执行配置单元自定义项

mcvgt66p  于 2021-06-29  发布在  Hive
关注(0)|答案(2)|浏览(419)

我有一个hiveudf,它在hiveterminal中运行良好,我想要的是通过shell脚本执行它。在配置单元终端上,我可以执行以下命令:

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脚本中添加上述代码时

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';"

第一个“hive-e”运行良好并添加了jar,但最后一个create temporary函数不起作用。我得到以下错误:

FAILED: ParseException line 1:35 mismatched input 'com' expecting StringLiteral near 'AS' in create function statement

我也尝试过单引号

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 ```
FAILED: Class com.mashery.nextdata.hive.udf.GeoIPGenericUDF not found

hiveudf是否支持shell脚本,如果它做了我正在做的错误的事情。提前谢谢
2izufjch

2izufjch1#

每次调用 hive -e 用一个新的配置单元外壳生成一个新进程,该配置单元外壳没有上一个配置单元外壳的内存,因此配置单元“忘记”udf在哪里。。。一种解决方案是只在一个命令中链接它们,但最好将所有配置单元命令放在一个文件中(例如“commands.hql”)并使用 hive -f commands.hql 而不是 -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';"
6qfn3psc

6qfn3psc2#

你可以让这两个一起工作 hive -e 以及 hive -f :

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 也行。

相关问题