Hive 表分区

基本知识:

    Hadoop:文件相关操作比如:

     hadoop fs -rmr 'hdfs://hdfs://192.168.8.101:8020/user/hive/warehouse';

     hadoop fs -put '/user/hive/warehouse/data.txt' 'hdfs://hdfs://192.168.8.101:8020/user/hive/warehouse/data.txt'

 

     创建分区表:

   

   外部表:

create external table if not exists employee(
id int,
name string,
dept string,
yoj int
)
partitioned by (
year string
)
row format delimited fields terminated by '\t'

   

  内部表:

  

create table if not exists employee(
id int,
name string,
dept string,
yoj int
)
partitioned by (
year string
)
row format delimited fields terminated by '\t'

 

 

   增加分区并加载数据

    1、 对于外部表

       <1 alter table employee add partition (year=‘2013’) location ‘hdfs://192.168.8.101:8020/user/hive/warehouse/hivedata/data’;      执行添加分区时   hivedata/    文件夹下的数据不会被移动。并且没有分区目录year=2013

      alter table employee drop partition (year=‘2013’);     执行删除分区目录时hivedata/    下的数据不会被删除

 

  <2  load data inpath 'hdfs://192.168.8.101:8020/user/hive/warehouse/hivedata/data' overwrite into table employee   partition(year='2013');    

    执行加载数据添加分区时 hivedata/     文件夹下的数据会被移动,并创建分区目录logdate=2015-02-26,数据移动到此目录下

        alter table employee drop partition (year='2013');     执行删除分区目录时,已经创建year=2013

分区目录不会被删除,其文件夹下的数据也不会被删除;

    

    2、内部表

         alter table employee add partition (year=‘2013’) location ‘hdfs://192.168.8.101:8020/user/hive/warehouse/hivedata/data’;      执行添加分区时   hivedata/    文件夹下的数据不会被移动。并且没有分区目录year=2013

       alter table employee drop partition (year=‘2013’);     执行删除分区时hivedata/    下的数据会被删除并且连同hivedata/文件夹也会被删除

      

       load data inpath 'hdfs://192.168.8.101:8020/user/hive/warehouse/hivedata/data' overwrite into table empl_inn  partition(year=2013);    
    执行加载数据添加分区时 
hivedata/     文件夹下的数据会被移动,并创建分区目录year=2013,数据移动到此目录下

        alter table employee drop partition (year=‘2013’);     执行删除分区目录时,已经创建year=2013  分区目录会被删除,其文件夹下的数据随之会被删除;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值