Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out if a Hive table is external or internal?

Tags:

I have multiple questions here. I am looking for any hive shell commands or queries to find the below details.

  1. Given a hive database name, how can I get the list of external tables in that database?

  2. Given a hive table name, how can I find out whether the table is external or internal?

Thanks in advance

like image 519
Sankar Avatar asked Jul 14 '14 07:07

Sankar


People also ask

How do you know if a table is managed table or external table in Hive?

For external tables Hive assumes that it does not manage the data. Managed or external tables can be identified using the DESCRIBE FORMATTED table_name command, which will display either MANAGED_TABLE or EXTERNAL_TABLE depending on table type.

How do I know what type of table is Hive?

In the Hive shell, get an extended description of the table. For example: DESCRIBE EXTENDED mydatabase. mytable; Scroll to the bottom of the command output to see the table type.

How do I find the location of an external table in Hive?

If you want to see the actual data storage location of hive table,you can use multiple ways . 1) hive> show create table <TableName>; It will provide you the table syntax long with where actual data located path . 2) describe extended table_name or describe formatted table_name .

What is an external table in Hive?

An external table is a table for which Hive does not manage storage. If you delete an external table, only the definition in Hive is deleted. The data remains. An internal table is a table that Hive manages. If you delete an internal table, both the definition in Hive and the data are deleted.


1 Answers

1) Given a hive database name, how can I get the list of external tables in that database ?

You can try this command:

SHOW TABLES [IN database_name] [identifier_with_wildcards]; 

It will give you all tables. As far as I know there is no direct command to know all the tables of type external/internal. For that you have use JDBC connection to connect to HiveMetastore and get the required info.

2) Given a hive table name, how can I find that whether the table is external or internal table ?

You can try any of this commands:

describe formatted table_name  describe extended table_name 

It show all the detail info of a table. Along with :

Table Type:             EXTERNAL_TABLE            Table Parameters:       EXTERNAL=TRUE 

Hope it helps...!!!

like image 135
Mukesh S Avatar answered Oct 13 '22 23:10

Mukesh S