简体   繁体   中英

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;

仅使用此语句(不使用alter table):

DROP TABLE external_hive_table;

1.Prevent data in external table from being deleted by a DROP TABLE statement.

ALTER TABLE table_name SET TBLPROPERTIES ('external.table.purge'='false');

2.Then DROP TABLE.

DROP TABLE table_name;

Reference: https://docs.cloudera.com/HDPDocuments/HDP3/HDP-3.1.4/using-hiveql/content/hive_drop_external_table_data.html

we can avoid this steep Boz for IF WE are drop external table it will drop the data will available in HDFS schema will be deleted . Script 2: Drop external table (drop data)

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

DROP TABLE external_hive_table

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM