当前位置:   article > 正文

【Hive-小文件合并】Hive外部分区表利用Insert overwrite的暴力方式进行小文件合并_hive合并分区

hive合并分区

这里我们直接用实例来讲解,Hive外部分区表有单分区多分区的不同情况,这里我们针对不同情况进行不同的方式处理。

  • 利用overwrite合并单独日期的小文件

1、单分区

# 开启此表达式:`(sample_date)?+.+` 
set hive.support.quoted.identifiers=none;

# 此sql是将20230713分区的小文件进行合并
# `(sample_date)?+.+`:表示select 出除了sample_date分区字段以外的所有字段(字段较多的时候用这种方式很便捷)
insert overwrite table `test`.`table` 
partition(sample_date='20230713') 
select `(sample_date)?+.+` 
from `test`.`table` where sample_date='20230713';
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

2、多分区

# 开启此表达式:`(sample_date|msgtype)?+.+`
set hive.support.quoted.identifiers=none;

# 此sql是将20230713分区的小文件进行合并(但是注意还有子分区:msgtype)
# `(sample_date|msgtype)?+.+`:表示select 出除了sample_date和msgtype这两个分区字段以外的所有字段(字段较多的时候用这种方式很便捷)
insert overwrite table `test`.`table` 
partition(sample_date='20230713') 
select `(sample_date|msgtype)?+.+` 
from `test`.`table` where sample_date='20230713';
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 利用overwrite合并一定分区范围内的小文件

1、单分区

注意: 合并一定分区范围内的小文件,select 后必须是 *,否则会报错。

insert overwrite table `test`.`table` 
partition(sample_date) 
select *
from `test`.`table` 
where sample_date between '20230712' and '20230713';
  • 1
  • 2
  • 3
  • 4
  • 5

2、多分区

注意: 合并一定分区范围内的小文件不管单分区还是多分区,select 后必须都是 *,否则会报错。

insert overwrite table `test`.`table` 
partition(sample_date, partition_name) 
select * 
from `test`.`table` 
where sample_date between '20230802' and '20230803';
  • 1
  • 2
  • 3
  • 4
  • 5
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/727927
推荐阅读
相关标签
  

闽ICP备14008679号