运行os命令并将输出设置为hive变量

时间:2014-12-11 00:47:19

标签: hive hiveql

是否可以在 Hive CLI 中运行类似的内容?

我正在尝试将文件内容作为变量传递给另一个查询。

set column_list=!cat /home/user/filename.lst ;
create table tabname as select $column_list from ...

2 个答案:

答案 0 :(得分:0)

如果您有查询文件,则将变量作为hiveconf传递 hive -hiveconf var1 = abcd -f file.txt

或者您可以构建查询,然后使用-e将其传递给hive cli hive -e"创建表..."

答案 1 :(得分:0)

file filename.lst

line

制作文件test.sh,

temp=$(cat /home/user/filename.lst)

hive -f test.hql -hiveconf var=$temp

制作另一个文件test.hql

create table test(${hiveconf:var} string);
终端上的

sh -x test.sh

它会将该行传递给test.hql,它将创建一个以行为列的表;

注意 - 所有文件都应该在同一目录中。这个脚本只传递一个变量。