Reputation:
I have multiple tables in Hive
with different schemas.
I want to select top 20 rows from each table and dump into csv file.
Is there any way to do it. As all I have found is to dump data from a single table to csv.
Any help would be appreciated!!
Upvotes: 0
Views: 122
Reputation: 1058
If you have different schema.
1.Below sample code will produce multiple csv files.
#!/bin/bash
tbs=$(hive -S -e "show tables")
for tb in $tbs
do
hive -e "set hive.cli.print.header=true; SELECT * FROM $tb LIMIT 20;" | sed 's/[\t]/,/g' > $tb.csv
done
2.Below sample code will produce single csv file.
#!/bin/bash
tbs=$(hive -S -e "show tables")
for tb in $tbs
do
echo "Table Name : "$tb >> sampleData.csv
hive -e "set hive.cli.print.header=true; SELECT * FROM $tb LIMIT 20;" | sed 's/[\t]/,/g' >> sampleData.csv
done
Upvotes: 1