Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I change a table from internal to external in hive?

I created a table in hive as a managed table, but it was supposed to be external, is it possible to change the table type of the table without losing the data?

like image 543
George TeVelde Avatar asked Aug 07 '12 05:08

George TeVelde


People also ask

Which is better external or internal table in Hive?

When you drop an internal table, it drops the data, and it also drops the metadata. When you drop an external table, it only drops the meta data. That means hive is ignorant of that data now. It does not touch the data itself.

How do I change the location of an internal table in Hive?

An internal table is stored on HDFS in the /user/hive/warehouse directory which is its default storage location. This location can be changed by updating the path in the configuration file present in the config file – hive. metastore. warehouse.

What happens when an internal table is dropped in Hive?

Regardless of the Internal and external table, Hive manages the table definition and its partition information in Hive Metastore. Dropping an internal table deletes the table metadata from Metastore and also removes all its data/files from HDFS.


2 Answers

ALTER TABLE <table> SET TBLPROPERTIES('EXTERNAL'='TRUE')

Note: EXTERNAL and TRUE need to caps or it will not work

like image 150
George TeVelde Avatar answered Oct 01 '22 03:10

George TeVelde


You can copy your data files from the Hive data location to the location you planned to store your external table, drop the table and re-create it as external.

like image 1
Olaf Avatar answered Oct 01 '22 02:10

Olaf