在 hive 中创建 TABLE 后添加 PARTITION

Add PARTITION after creating TABLE in hive

我已经创建了一个非分区 table 并将数据加载到 table,现在我想在 table 的基础上添加一个 PARTITION ,我可以这样做吗? 如果我这样做:

ALTER TABLE Student ADD PARTITION (dept='CSE') location '/test';

它给我错误:

FAILED: SemanticException table is not partitioned but partition spec exists: {dept=CSE}

请帮忙。谢谢

首先创建一个 table,这样 table 中就没有分区列了。

create external table Student(col1 string, col2 string) partitioned by (dept string) location 'ANY_RANDOM_LOCATION';

完成 table 的创建后,更改 table 以添加 像这样明智地划分部门:

alter table Student add partition(dept ='cse') location '/test';

希望对您有所帮助。

如果在创建 table 时未定义分区,则无法更改 table 分区。

如果在更改未分区的 table 以添加分区时出现此错误:"Semantic Exception table is not partitioned but partition spec exists: {dept=CSE}," 这意味着您正试图将分区包含在 table 本身中。

您没有收到语法错误,因为命令的语法是正确的并且用于更改分区列。

了解有关 Hive 表的更多信息:

https://www.dezyre.com//hadoop-tutorial/apache-hive-tutorial-tables

您还可以在table中检查可能的交替:

https://sites.google.com/site/hadoopandhive/home/how-to-create-table-partition-in-hive

希望对您有所帮助。