【问题标题】:How to merge existing hourly partitions to daily partition in hive如何将现有的每小时分区合并到 hive 中的每日分区
【发布时间】:2019-06-25 03:54:57
【问题描述】:

我的要求是将现有的每小时分区合并到所有天的每日分区。

我的分区列是这样的:

2019_06_22_00, 2019_06_22_01, 2019_06_22_02, 2019_06_22_03..., 2019_06_22_23 => 2019_06_22
2019_06_23_00, 2019_06_23_01, 2019_06_23_02, 2019_06_23_03..., 2019_06_23_23 => 2019_06_23

【问题讨论】:

    标签: merge hive partitioning hadoop-partitioning hive-partitions


    【解决方案1】:

    简单的方法是从当前分区列中提取日期并加载到新表中。

    创建新表:

    create table new (
    ...
    ) 
    partitioned by (partition_date date);
    

    然后从旧表插入覆盖:

    set hive.exec.dynamic.partition=true;
    set hive.exec.dynamic.partition.mode=nonstrict;
    
    insert overwrite table new partition(partition_date )
    select
    col1,
    col2,
    ...
    coln,
    --extract hours if you need this column
    substr('old_partition_col',12,2) hour,
    --partition column is the last one
    date(concat_ws('-',substr(old_partition_col,1,4),substr(old_partition_col,6,2),substr(old_partition_col,9,2))) as partition_date 
    from old_table;
    

    您也可以使用unix_timestampfrom_unixtime 函数提取日期:

    from_unixtime(unix_timestamp(old_partition_col,'yyyy_MM_dd_HH'),'yyyy-MM-dd') as partition_date
    

    然后删除旧表并重命名新表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-24
      • 1970-01-01
      • 2018-12-28
      • 2018-08-28
      • 2021-11-05
      • 2013-08-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多