count columns in Hive

Anyone know a query to count the number of columns in a table using a Hive QL?
Ex : if the table "t1" has columns c1,c2, (where n can be 200+), i want to know the number of columns using a hive QL, the output of the Hive QL should be columns=223.

2 Answer(s)


Hive columns you can find in metdata, which would be static based on the create command.
you can simple get the all column names the below command

hive -e "show create table $TABLE_NAME"

For a particular record, if you wanted to find columns then you have to read that record.


use below commands from shell:
>count = hive -S -e 'describe ' | wc -l;
>echo $count;