Support Questions

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

Beeline file name parameterize

avatar
New Contributor

I have a directory of say 10 SQL files and out of which I need to run only 5 SQL files. I am trying to achieve this by creating an array of only the five files that I need to execute and trying to call Beeline -f in for loop to execute the files . But the solution does not seem to be working . The SQL can be triggered when I run beeline -f mysqlfile.sql  

 

for eachline in "${testarray[@]}"
do
beeline -f '${eachline}'.sql
done

 

3 REPLIES 3

avatar
Super Guru

@Caliber ,

 

Not sure if this is the problem, but beeline has a known issue with terminal settings when running in the background.

 

Try adding this to your script, before the for loop:

export HADOOP_OPTS=-Djline.terminal=jline.UnsupportedTerminal

 

Cheers,

André

 

--
Was your question answered? Please take some time to click on "Accept as Solution" below this post.
If you find a reply useful, say thanks by clicking on the thumbs up button.

avatar
Master Collaborator

@Caliber The following command should work:

# for hql in {a.hql,b.hql}; do beeline -n hive -p password --showheader=false --silent=true -f $hql; done

avatar
Super Collaborator

It seems like there might be an issue with the way you're using single quotes in the loop. The variable eachline should be expanded, but it won't if it's enclosed in single quotes. Try using double quotes around the variable and see if that resolves the issue. Here's the corrected loop:

 
 

 

for eachline in "${testarray[@]}"
do
  beeline -f "${eachline}.sql"
done

 

This way, the value of eachline will be correctly expanded when constructing the command. Also, ensure that the SQL files are present in the correct path or provide the full path if needed. If the issue persists, please provide more details on the error message or behavior you're experiencing for further assistance.