Reputation: 213
Is it possible to retrieve column names from a table and load them into another table or a text file in hive? Please let me know if we can do this
Upvotes: 6
Views: 25856
Reputation: 654
A bit more succinct version
hive -S -e "SHOW COLUMNS IN database_name.table_name" > column_names.txt
Upvotes: 8
Reputation: 2496
Another solution is by using hive.cli.print.headers=true
This is what I am using for getting the headers as comma separated. Replace database and table accordingly:
hive -S -e 'SET hive.cli.print.header=true; SELECT * FROM database.table LIMIT 0' | sed -e 's/\t/,/g' > headers.txt
Upvotes: 6
Reputation: 34184
There is no OOTB feature which allows this. But you could use DESCRIBE with awk to achieve that :
bin/hive -S -e "use default; describe demo;" | awk -F" " '{print $1}' > ~/filename.txt
Replace default and demo with database and table you want to operate on.
Upvotes: 6