run os command and set out put to hive variable

2019-08-29 11:46发布

问题:

Is it possible to run something like this in Hive CLI?

I am trying to pass file contents as a variable to another query.

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

回答1:

if you have a query file you pass the variables as hiveconf hive -hiveconf var1=abcd -f file.txt

or you can construct your query and then pass it to hive cli using -e hive -e "create table ..."



回答2:

file filename.lst

line

make a file test.sh,

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

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

make a another file test.hql

create table test(${hiveconf:var} string);

on terminal

sh -x test.sh

It will pass the line to the test.hql and it will create a table with line as column;

note- all files should be in same directory .This script is passing only one variable.



标签: hive hiveql