zoukankan      html  css  js  c++  java
  • Hive-删除表(drop、truncate的区别)

    Hive删除操作主要分为几大类:删除数据(保留表)、删除库表、删除分区。我将以下图为例清空iot_devicelocation中的数据,之后再删除表、库等。

     解释:

     use xpu123;   #使用的库为xpu123
     show tables;  #显示该库中的所有的表名

    首先来看一下iot_deivcelocation中的数据。select * from iot_deivcelocation。

     

    一、仅删除表中数据,保留表结构

    hive> truncate table iot_devicelocation;
    truncate操作用于删除指定表中的所有行,相当于delete from table where 1=1.表达的是一个意思。

    注意:truncate 不能删除外部表!因为外部表里的数据并不是存放在Hive Meta store中。创建表的时候指定了EXTERNAL,外部表在删除分区后,hdfs中的数据还存在,不会被删除。因此要想删除外部表数据,可以把外部表转成内部表或者删除hdfs文件。

     

    二、删除表

    hive> drop table if exists iot_devicelocation;
    drop table if exists table_name;

     

    三、删除库

    hive> drop database if exists xpu123;
    drop database if exists database_name;但是根据第二步操作结束,我们的数据库xpu123中,还存在iot_deviceenergytype表,因此,如果直接删除,会报以下错误。Hive会提醒你,将要执行删除操作的xpu123的库里面还存在tables。

     

    解决这个错误有两种方法:一、就是很简单的将所有表先删除完,再删除库。

    另外一种就是使用下述的方法:使用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');

    参考:https://blog.csdn.net/a_drjiaoda/java/article/details/94433005

  • 相关阅读:
    21.Merge Two Sorted Lists 、23. Merge k Sorted Lists
    34. Find First and Last Position of Element in Sorted Array
    leetcode 20. Valid Parentheses 、32. Longest Valid Parentheses 、301. Remove Invalid Parentheses
    31. Next Permutation
    17. Letter Combinations of a Phone Number
    android 常见分辨率(mdpi、hdpi 、xhdpi、xxhdpi )及屏幕适配注意事项
    oc 异常处理
    oc 类型判断
    oc Delegate
    oc 协议
  • 原文地址:https://www.cnblogs.com/Formulate0303/p/12840688.html
Copyright © 2011-2022 走看看