I have a hive query that is working fine. but when I want to run this in a shell script I am unable to make it to work.
Below is the shell script.
#!/bin/bash
start_date='2019-08-01'
end_date='2019-08-31'
while IFS='|' read -r table_name val;
do
hive -e "set hive.cli.print.header=true;select source_to_date, target_count from testing.log_final where project_name= '${val}' and source_to_date between '${start_date}' and '${end_date}' order by source_to_date;" | sed 's/[\t]/,/g' > /x/home/SUER/btree/"${table_name}".csv
done < /x/home/"$USER"/bt_tables.txt
Contents of bt_tables.txt:
merchants|102_merchants_project
payments|103_payments_project
Query that works fine:
hive -e "set hive.cli.print.header=true;select source_to_date, target_count from testing.log_final where project_name= '102_merchants_project' and source_to_date between '2019-08-01' and '2019-08-31' order by source_to_date;" | sed 's/[\t]/,/g' > /x/home/SUER/btree/merchants.csv
What am I doing wrong here?
echo "hive -e set hive.cli.print.header=true; d select source_to_date, target_count from testing.log_final where project_name='${val}' and source_to_date between '${start_date}' and '${end_date}' order by source_to_date;"