I have created an external table in Impala. I am writing a shell script which checks whether a particular column exists in that table.
We can do this in MySql using the following query.
SELECT *
FROM information_schema.COLUMNS
WHERE
TABLE_SCHEMA = 'db_name'
AND TABLE_NAME = 'table_name'
AND COLUMN_NAME = 'column_name'
But, in Impala, how can we achieve this?
Unfortunately you cannot query the schema metadata in Impala. You can use describe table
(see the documentation) and check the output.
There is SHOW Statement in Cloudera Impala:
The SHOW statement is a flexible way to get information about different types of Impala objects.
For your use case you can use SHOW COLUMN STATS Statement, e.g.:
SHOW COLUMN STATS myTableName
It will return following information:
+------------------------+--------+------------------+--------+----------+----------+
| Column | Type | #Distinct Values | #Nulls | Max Size | Avg Size |
+------------------------+--------+------------------+--------+----------+----------+
| my_column_id | INT | -1 | -1 | 4 | 4 |
| my_string_column_name | STRING | -1 | -1 | -1 | -1 |
| some_column_name | INT | -1 | -1 | 4 | 4 |
...
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