Djeah
Djeah

Reputation: 360

Export multiple output of queries in the same hive session to shell script?

Is there a way to export the output of multiple hive queries in the hive CLI to the shell script?

Currently, I have shell script wherein there are multiple hive queries which I fire:

VAR1=`hive -e "select count(*) from table1;"`
VAR2=`hive -e "select count(*) from table2;"`
VAR3=`hive -e "select count(*) from table3;"`

This will run all the queries in a separate hive session which will cause it to wait for resources in yarn. Instead, I want to run them in the same hive session

`hive -e "select count(*) from table1;select count(*) from table2;select count(*) from table3;"`

and get the output passed to the shell script into VAR1, VAR2 & VAR3. Is it possible?

Upvotes: 0

Views: 477

Answers (1)

OneCricketeer
OneCricketeer

Reputation: 191681

Try a sub query

select c1.*, c2.*, c3.* from 
(select count(*) from table1) c1, 
(select count(*) from table2) c2, 
(select count(*) from table3) c3;

Upvotes: 3

Related Questions