简体   繁体   中英

How to write hive script for return result in shell variable in an Oozie coordinator?

Then i coordinate my script.sh in an Oozie there is nothing in a variables S. Here is shell script

S=$(hive -S -hiveconf MY_VAR1=$DB -hiveconf MY_VAR2=$avgpay -hiveconf MY_VAR3=$Date_LastDay -hiveconf MY_VAR4=$Date_LastNmonth -f bpxp.hql)

echo $S "S"


S1=( $( for k in $S ; do echo $k ; done ) )
    cntn=${#S1[@]}
    for (( p=0 ; p<$cntn; p=p+5 ))
 do
     `mysql -h$mysqlhost -u$mysqluser -p$mysqlpass $mysqldb -e "INSERT INTO weekstat (timeshift, partnerid, avg_value, processdate, weekday) VALUES ('${S1[p]}', '${S1[p+1]}', '${S1[p+2]}', '${S1[p+3]}', '${S1[p+4]}');"`
done

Mysql commands works fine with another variables Here is bpxp.hql

...

    hive -e "select * from ${hiveconf:MY_VAR1}.weekstat;"

Then i run script from shell it works fine. I try to use bpxp.hql without this line hive -e "select * from ${hiveconf:MY_VAR1}.weekstat;" and write it in shell S= hive -e "select * from $DB.weekstat;" but nothing change. Where is my mistake?

Whatever you done is an efficient way, but minor change as mentioned below:

S=$(hive -S -hiveconf MY_VAR1=$DB -hiveconf MY_VAR2=$avgpay -hiveconf MY_VAR3=$Date_LastDay -hiveconf MY_VAR4=$Date_LastNmonth -f bpxp.hql)

In bpxp.hql keep the query

select * from $DB.weekstat;

You don't need to mention hive -e in the hql script, the command above will automatically executes and gives you the output, and stores into S.

Please let me correct if I'm wrong.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM