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


    这里我们直接用实例来讲解,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
  • 相关阅读:
    Python爬虫入门基础学习(二)
    成人自考-英语二-形容词
    Java 如何借助InputStream读取网络图片呢?
    trivy【2】工具漏洞扫描
    STM32:TIM通道输入捕获
    SQL语句
    vue中使用接口(搜狐接口)获取访客IP地址
    (一)大白话MySQL执行SQL的流程
    OpenCV图像加载、显示与保存
    k8s之创建基于sa的访问凭据kubeconfig文件
  • 原文地址:https://blog.csdn.net/weixin_53543905/article/details/132695437