仅当HIVE中不存在分区时才如何插入覆盖分区?
就像标题一样。我正在做一些总是需要重写配置单元表的事情。我的表具有多个分区,在更改后重新运行代码时,我只想插入新分区而不更改存在的分区。
您可以加入现有分区列表,并在条件为NULL的地方添加(不只加入)。您也可以使用NOT EXISTS(它将生成与Hive中的左连接相同的计划),如下所示:
insert overwrite table target_table partition (partition_key)
select col1, ... coln, s.partition_key
from source s
left join (select distinct partition_key --existing partitions
from target_table
) t on s.partition_key=t.partition_key
where t.partition_key is NULL; --no partitions exists in the target
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句