How to create a unix script to loop a Hive SELECT query by taking table names as input from a file?
Simple working shell script:
db=mydb for table in $(hive -S -e "use $db; show tables;") do #echo "$table" hive -S -e "use $db; select '$table' as table_name, count(*) as cnt from $table;" done
You can improve this script and generate file with select commands or even single select with union all
, then execute file instead of calling Hive for each table.
If you want to read table names from file, use this:
for table in filenamedo ...done