hive table 有多个分区字段时,如何只更新一个分区字段?
How to update only one partition field when the hive table has multiple partition fields?
我有一个名为 table
的 Hive table,它有两个字符串分区字段,years
和 month
。现在我只想更新 years
分区而不更新 month
分区。
我尝试了下面的 sql 但失败了。
ALTER TABLE table PARTITION (years='2021') RENAME TO PARTITION (years='2020');
Apache 方解石记录了
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
由于分区是一个文件夹结构,您需要提及所有分区名称。
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');
...
否则您可以创建一个新的 table 结构相同但由新分区进行分区。然后从旧的 table 插入到新的 table 然后删除新的 table.
我有一个名为 table
的 Hive table,它有两个字符串分区字段,years
和 month
。现在我只想更新 years
分区而不更新 month
分区。
我尝试了下面的 sql 但失败了。
ALTER TABLE table PARTITION (years='2021') RENAME TO PARTITION (years='2020');
Apache 方解石记录了
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
由于分区是一个文件夹结构,您需要提及所有分区名称。
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');
...
否则您可以创建一个新的 table 结构相同但由新分区进行分区。然后从旧的 table 插入到新的 table 然后删除新的 table.