简体   繁体   中英

Add PARTITION after creating TABLE in hive

i have created a non partitioned table and load data into the table,now i want to add a PARTITION on the basis of department into that table,can I do this? If I do:

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

It gives me error:

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

please help. Thanks

First create a table in such a way so that you don't have partition column in the table.

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

Once you are done with the creation of the table then alter the table to add the partition department wise like this :

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

I hope this will help.

You can't alter table partition if you didn't define partition while creation of table.

If, when altering a un-partitioned table to add partition, you get this error: "Semantic Exception table is not partitioned but partition spec exists: {dept=CSE}," it means you are trying to include the partitioned in the table itself.

You are not getting syntax error because the syntax of the command is correct and used to alter the partition column.

Learn more about Hive Tables:

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

You can also check the possible alternation in table:

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

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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