Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

how to use loop in hive

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

Re: how to use loop in hive

Rising Star

@Anbu Eswaran

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

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?

Re: how to use loop in hive

New Contributor

Thanks its working fine now. sorry for the delay reply

Re: how to use loop in hive

Mentor

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

Don't have an account?
Coming from Hortonworks? Activate your account here