Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

how to use loop in hive

avatar
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

avatar
Expert Contributor

@Anbu Eswaran

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

avatar
Super Collaborator

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

avatar
Expert Contributor

Hi @Mahesh Mallikarjunappa

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

avatar
New Contributor

Thanks its working fine now. sorry for the delay reply

avatar
Master Mentor

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