2016-05-13 35 views
0

我有一个Hive Udf在hive终端中运行良好,我想通过shell脚本执行它。 在蜂巢终端,我能够执行下面的命令:通过shell脚本配置单元udf执行

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

首届“蜂巢-e”运作良好,并增加了罐子但最后一个创建临时功能不起作用。我得到以下错误:

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 

是否不亦乐乎UDF支持shell脚本,如果这样做什么我正在做错。在此先感谢

+3

尝试导入jar并创建一个调用蜂巢的函数。即'hive -e'添加jar path_to_jar/foo.jar;创建临时函数foo作为'com.package.UDF';'' – gobrewers14

+0

@ GoBrewers14感谢它为我工作:-) –

回答

1

hive -e的每次调用产生一个新的蜂窝shell,没有记忆的前一个做的记录,所以蜂巢'忘记'的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';" 
0

你能得到这个既hive -ehive -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将正常工作。