问题
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