如何遍历配置单元中的所有分区?

How to go through all partitions in hive?

我想更新所有分区中的列值。之前我发现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 中的所有分区?非常感谢。

您可以使用 dynamic partitioning 完成此类任务

使用动态分区:

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;