How to go through all partitions in hive?

怎甘沉沦 提交于 2019-12-24 08:09:39

问题


I want to update column's value in all partitions. Before I found insert overwrite can be used to update data. My current statement is

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

However, it must specify certain partition. What I want is to update the value in all partitions, I don't know how to do. Is there a way using hive sql to go through all partitions in hive? Thank you so much.


回答1:


Use 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;



回答2:


You can use dynamic partitioning for such type of tasks



来源:https://stackoverflow.com/questions/55134135/how-to-go-through-all-partitions-in-hive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!