2016-10-12 159 views
0

我正在編寫hive腳本,我需要在hive腳本中讀取hdfs中的文件,並在hive查詢中使用文件內容。 hdfs中的文件包含單行的日期。在hive腳本中執行unix命令

我知道我們可以通過使用'!'在hive shell中使用unix命令,但是我需要使用下面的命令,它不適用於!

while IFS= read -r line; do snapshot_id=$line done < <(hadoop fs -cat /hdfs_path/date.txt) 

select * from <tablename> where datestring = $snapshot_id 

是否可能。 ?

回答

0

這類似於你需要什麼,

#!/bin/bash 

old_IFS=$IFS 
IFS=$'\n' 
for line in $(hadoop fs -cat /hdfs_path/date.txt) 
do 
    hive -f "select * from test where datestring = $line" 
done   
IFS=$old_IFS 

希望這有助於

+0

我不想shell腳本。我需要hql腳本,我將從oozie執行它 –

+1

爲什麼不能在oozie中運行shell而不是hive動作 –

+1

爲什麼不能同時運行?您應該能夠將shell操作的參數傳遞給配置單元操作 – JitterbugChew