Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop Hive external table WITHOUT removing data

The goal is to destroy a Hive schema but keep the data underneath.

Given a Hive external table, created for example with script 1, it can be dropped with script 2. This deletes the data (removes the folder /user/me/data/). This folder has to remain for use in other projects.

A long search does not yield anything so far...

Script 1: Create an external table

CREATE EXTERNAL TABLE external_hive_table(
    column1 STRING
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY
    '\t'
STORED AS TEXTFILE
LOCATION
   '/user/me/data/'
TBLPROPERTIES (
    "skip.header.line.count"="1");

Script 2: Drop external table (drop data)

ALTER TABLE
    external_hive_table
SET TBLPROPERTIES (
    'EXTERNAL'='FALSE');

DROP TABLE external_hive_table;

Edit: Script 3: Drop external table (keep data)

 DROP TABLE external_hive_table;
like image 780
Laurens Koppenol Avatar asked Nov 23 '16 09:11

Laurens Koppenol


People also ask

Does dropping an external table delete the data?

Dropping an external table removes all table-related metadata. It doesn't delete the external data.

What happens when we drop external table in Hive?

External tables are stored outside the warehouse directory. They can access data stored in sources such as remote HDFS locations or Azure Storage Volumes. Whenever we drop the external table, then only the metadata associated with the table will get deleted, the table data remains untouched by Hive.


1 Answers

Use only this statement (without alter table):

DROP TABLE external_hive_table;
like image 118
facha Avatar answered Oct 17 '22 07:10

facha