2016-10-12 160 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