在hive中创建TABLE后添加PARTITION

rin*_*ain 17 hadoop hive partition

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

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

它给了我错误:

FAILED: SemanticException table is not partitioned but partition spec exists: {dept=CSE}
Run Code Online (Sandbox Code Playgroud)

请帮忙.谢谢

Nar*_*esh 9

首先以这种方式创建一个表,以便表中没有分区列.

create external table Student(col1 string, col2 string) partitioned by (dept string) location 'ANY_RANDOM_LOCATION';
Run Code Online (Sandbox Code Playgroud)

完成表的创建后,然后更改表以便像这样添加分区部门:

alter table Student add partition(dept ='cse') location '/test';
Run Code Online (Sandbox Code Playgroud)

我希望这将有所帮助.


小智 5

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

如果在更改未分区的表以添加分区时出现以下错误:“语义异常表未分区,但分区规范存在:{dept = CSE}”,则表示您试图将分区包括在表本身中。

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

了解有关蜂巢表的更多信息:

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

您还可以在表中检查可能的替换:

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

希望这可以帮助。