Search code examples
bashhive

running a hive query via cli with columns containing special characters


I'm writing a bash script, and have to go through a lot of tables with a lot of columns containing special characters ( mainly spaces ) I want to change them with underscores and I have this code so far:

while read column;do

    beeline  -e  "use DB; ALTER TABLE X CHANGE `${column}` ${column// /_} STRING;"

done < ./file_with_column_names.txt

I wrap the column name in back-ticks and everything should work but I get an error, regardless if the column the script is trying to change has special characters or not:

FAILED: ParseException line 1:49 cannot recognize input near '<EOF>' '<EOF>' '<EOF>' in column type (state=42000,code=40000)

However, same query ran from HUE ( obviously the bash variables replaces with column names) works fine.

I don't know why the beeline query fails. Any ideas? Thanks!


Solution

  • OK, I discovered the reason. The backticks are also interpreted by BASH, so i need to escape them also like so

    \`${column}\`