Hive operation - delete a table (drop, truncate)

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/a_drjiaoda/article/details/94433005

Hive delete operations are divided into several categories: deleting data (reserved table), delete database tables, delete partitions. I empty the following figure as an example of data iot_devicelocation, then you delete the table, library and so on.

First look at the data in the iot_deivcelocation. select * from iot_deivcelocation.

First, delete the data in the table only to retain the table structure

hive> truncate table iot_devicelocation;

truncate operation is used to delete all lines of the table corresponds to delete from table where 1 = 1. The expression is a meaning.

Note: TRUNCATE can not delete the external table! Because the external table of data is not stored in the Hive Meta store. Create table when the specified EXTERNAL, an external after deleting the partition table, the data hdfs there will not be deleted. Therefore, in order to delete the external table data, you can put external table into an internal table or delete hdfs file.

Second, delete the table

hive> drop table if exists iot_devicelocation;

drop table if exists table_name;

Third, delete the library

hive> drop database if exists xpu123;

 drop database if exists database_name; but according to the end of the second step, our database xpu123, there is also iot_deviceenergytype table, so if you delete, the following error will be reported. Hive will remind you, will be performed xpu123 library deletion of which there are tables.

There are two ways to resolve this error: a, is a very simple table to delete all finished, and then delete the library.

另外一种就是使用下述的方法:使用cascade关键字执行强制删库。drop database if exists xpu123 cascade; 如下所示

四、删除hive分区

alter table table_name drop partition (partition_name='分区名')

hive> alter table tablename drop partition(load_date='2019-01-01');

 

Guess you like

Origin blog.csdn.net/a_drjiaoda/article/details/94433005