Friday, January 11, 2013

Bash single quote escape in running a Hive query

If you want to run this hive query using SSH, you probably will be headache how to escape:
select * from my_table where date_column = '2013-01-11';
The correct command looks like this:
ssh myserver 'hive -e "select * from my_table where date_column = '"'2013-01-11'"';"'
What hack? Here is how bash read this:
1. ssh
2. myserver
3. hive -e "select * from my_table where date_column = 
4. '2013-01-01'
5. ;"
3,4,5 will be concatenated to one line
hive -e "select * from my_table where date_column = '2013-01-01';"