2016-05-13 102 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將正常工作。