【问题标题】:How to go through all partitions in hive?如何遍历 hive 中的所有分区?
【发布时间】:2019-03-13 13:44:25
【问题描述】:

我想更新所有分区中列的值。之前我发现insert overwrite可以用来更新数据。我目前的说法是

insert OVERWRITE table s_job PARTITION(pt = '20190101') select case job_name when 'Job' then 'system' end from s_job;

但是,它必须指定特定的分区。我想要的是更新所有分区中的值,我不知道该怎么做。有没有办法使用 hive sql 遍历 hive 中的所有分区?非常感谢。

【问题讨论】:

    标签: sql hive hiveql partition


    【解决方案1】:

    使用动态分区:

    set hive.exec.dynamic.partition=true;
    set hive.exec.dynamic.partition.mode=nonstrict;
    
    insert OVERWRITE table s_job PARTITION(pt) 
    select --Add all columns in their original order
           col1,
           col2,
           ...
           coln,
           case job_name when 'Job' then 'system' end as job_name,
           pt --partition column should be the last one
      from s_job;
    

    【讨论】:

      【解决方案2】:

      您可以将dynamic partitioning 用于此类任务

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-03-15
        • 2011-11-04
        • 1970-01-01
        • 2019-11-18
        • 2018-12-28
        • 1970-01-01
        • 2015-05-18
        相关资源
        最近更新 更多