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?
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.
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.
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.
ALTER TABLE <table> SET TBLPROPERTIES('EXTERNAL'='TRUE')
Note: EXTERNAL and TRUE need to caps or it will not work
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.
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