简体   繁体   English

hive表有多个分区字段时,如何只更新一个分区字段?

[英]How to update only one partition field when the hive table has multiple partition fields?

I have a Hive table called table , it has two string partition field, years and month .我有一个名为table的 Hive 表,它有两个字符串分区字段, yearsmonth Now I only want to update the years partition but not update month partition.现在我只想更新years分区而不是更新month分区。

I tried the sql below but failed.我尝试了下面的 sql 但失败了。

ALTER TABLE table PARTITION (years='2021') RENAME TO PARTITION (years='2020');

Apache calcite logged that Apache calcite 记录了这一点

org.apache.calcite.runtime.CalciteContextException: Sql 1: From line 1, column 43 to line 1, column 84: Number of target table partition columns 2 does not equal number of source partition columns 1 org.apache.calcite.runtime.CalciteContextException:Sql 1:从第 1 行第 43 列到第 1 行第 84 列:目标表分区列 2 的数量不等于源分区列 1 的数量

Since partition is a folder structure, you need to mention all partition names.由于分区是文件夹结构,因此您需要提及所有分区名称。

ALTER TABLE table PARTITION (years='2021',month='1') RENAME TO PARTITION (years='2020',month='1');
ALTER TABLE table PARTITION (years='2021',month='2') RENAME TO PARTITION (years='2020',month='2');
ALTER TABLE table PARTITION (years='2021',month='3') RENAME TO PARTITION (years='2020',month='3');
...

Or else you can create a new table with same structure but partitioned by new partition.或者,您可以创建一个具有相同结构但由新分区分区的新表。 And then insert from old table to new table and then drop the new table.然后从旧表插入到新表,然后删除新表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM