I know of these,
To get column names in a table we can fire:
show columns in <database>.<table_name>
To get description of a table (including column_name, column_type and many other details):
describe [formatted] <database>.<table_name>
I know that I can use the above query and filter the result to get the columns names and types. But I want to know if there is any direct command to get just the column names and types like select columns, column_type ...
?
If you're executing any SELECT statement on Hive cli, only the rows are displayed. The column names are not displayed by default. To show the column headers, print. header property needs to be set to true.
use desc tablename from Hive CLI or beeline to get all the column names.
The easiest way to select specific columns in the Hive query is by specifying the column name in the select statement. SELECT col1, col3, col4 .... FROM Table1; But imagine your table contains many columns (i.e : more than 100 columns) and you need to only exclude a few columns in the select statement.
DESCRIBE shows/displays the list of columns (including partition columns) for the given table. EXTENDED, FORMATTED keyword is optional. If the EXTENDED is specified, it show/displays all the metadata for the specified table. If the FORMATTED is specified, it show/displays the metadata in a tabular format.
In HIVE you could use:
DESCRIBE FORMATTED [DatabaseName].[TableName] [Column Name];
This gives you the column data type and some stats of that column.
DESCRIBE [DatabaseName].[TableName] [Column Name];
This just gives you the data type and comments if available for a specific column.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With