福建省人民政府辦公廳洛陽(yáng)seo網(wǎng)站
這里我們直接用實(shí)例來(lái)講解,Hive外部分區(qū)表有單分區(qū)多分區(qū)的不同情況,這里我們針對(duì)不同情況進(jìn)行不同的方式處理。
- 利用overwrite合并單獨(dú)日期的小文件
1、單分區(qū)
# 開(kāi)啟此表達(dá)式:`(sample_date)?+.+`
set hive.support.quoted.identifiers=none;# 此sql是將20230713分區(qū)的小文件進(jìn)行合并
# `(sample_date)?+.+`:表示select 出除了sample_date分區(qū)字段以外的所有字段(字段較多的時(shí)候用這種方式很便捷)
insert overwrite table `test`.`table`
partition(sample_date='20230713')
select `(sample_date)?+.+`
from `test`.`table` where sample_date='20230713';
2、多分區(qū)
# 開(kāi)啟此表達(dá)式:`(sample_date|msgtype)?+.+`
set hive.support.quoted.identifiers=none;# 此sql是將20230713分區(qū)的小文件進(jìn)行合并(但是注意還有子分區(qū):msgtype)
# `(sample_date|msgtype)?+.+`:表示select 出除了sample_date和msgtype這兩個(gè)分區(qū)字段以外的所有字段(字段較多的時(shí)候用這種方式很便捷)
insert overwrite table `test`.`table`
partition(sample_date='20230713')
select `(sample_date|msgtype)?+.+`
from `test`.`table` where sample_date='20230713';
- 利用overwrite合并一定分區(qū)范圍內(nèi)的小文件
1、單分區(qū)
注意: 合并一定分區(qū)范圍內(nèi)的小文件,select 后必須是 *
,否則會(huì)報(bào)錯(cuò)。
insert overwrite table `test`.`table`
partition(sample_date)
select *
from `test`.`table`
where sample_date between '20230712' and '20230713';
2、多分區(qū)
注意: 合并一定分區(qū)范圍內(nèi)的小文件不管單分區(qū)還是多分區(qū),select 后必須都是 *
,否則會(huì)報(bào)錯(cuò)。
insert overwrite table `test`.`table`
partition(sample_date, partition_name)
select *
from `test`.`table`
where sample_date between '20230802' and '20230803';