Support Questions
Find answers, ask questions, and share your expertise

how to use loop in hive

Highlighted

how to use loop in hive

New Contributor

I want to insert the table more than 100. Is it possible to do it in for loop in hql. if yes, please share it

5 REPLIES 5
Highlighted

Re: how to use loop in hive

Rising Star

@Anbu Eswaran

Just add the records to a file and LOAD the file to Hive.

Highlighted

Re: how to use loop in hive

Expert Contributor

HI,

Please refer below example.

With a little bash we can loop through all our tables, appending the results to a file: #get a list of the files

hive -e "show tables;" > hivetables.txt

Now — cool stuff:

for line in $(cat hivetables.txt) ; 
do 
     results=$(hive -hiveconf tablename=$line -f test.hql) 
     echo $results >> tablecounts.txt 

done

Hope this will be helpful.

Thanks,

Mahesh

Highlighted

Re: how to use loop in hive

Contributor

Hi @Mahesh Mallikarjunappa

what is the purpose of test.hql? logic behind it?

Highlighted

Re: how to use loop in hive

New Contributor

Thanks its working fine now. sorry for the delay reply

Highlighted

Re: how to use loop in hive

Mentor

@Anbu Eswaran please select the best answer as we don't know which answer helped most.