hive的分区(二)

动态分区的设置

  1. 分区的类型
    静态分区:加载数据到指定的分区的值
    动态分区:数据未知,根据分区的值确定创建分区
    混合分区:静态和动态都有

  2. 动态分区的设置
    hive.exec.dynamic.partition=true/false --是否支持动态分区
    hive.exec.dynamic.partition.mode=strict/nostrict --严格/非严格
    hive.exec.max.dynamic.partitions=1000 --默认一个
    hive.exec.max.dynamic.partitions.pernode=100
    严格模式下会阻止以下三种查询:

  • 对分区表查询,where条件中过滤字段不是分区字段
  • 笛卡尔积的join不使用on条件或者where条件
  • 对order by 查询不带limit语句
  1. 创建动态分区
    create table dy_part1(
    id int,
    name string
    )
    partitioned by (dt string)
    row format delimited fields terminated by ‘,’
    ;
    . 先创建临时表:

    create table temp_part(
    id int,
    name string,
    dt string
    )
    row format delimited fields terminated by ‘,’;
    . 导入数据到临时表:
    load data local inpath ‘/hivedata/t4.txt’ into table temp_part;
    . 动态加载到表
    insert into dy_part1 partition(dt) select id,name,dt from temp_part;

混合分区

  1. 建表:

create table dy_part2(
id int,
name string
)
partitioned by (year string,month string,day string)
row format delimited fields terminated by ‘,’
;

  1. 创建临时表

      create table temp_part2(
     id int,
     name string,
     year string,
     month string,
     day string
     )
     row format delimited fields terminated by ','
     ;
     导入数据
     insert into dy_part2 partition (year='2018',month,day)
     select id,name,month,day from temp_part2;
    

分区表注意事项

  1. hive的分区使用的是表外字段,分区字段是一个伪列,但是分区字段是可以做查询过滤。
  2. 分区字段不建议使用中文
  3. 一般不建议使用动态分区,因为动态分区会使用mapreduce来进行查询数据,如果分区数据过多,导致namenode和resourcemanager的性能瓶颈。所以建议在使用动态分区前尽可能预知分区数量。
  4. 分区属性的修改都可以使用修改元数据和hdfs数据内容。
  5. Hive分区和Mysql分区的区别
    mysql分区字段用的是表内字段;而hive分区字段采用表外字段。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值