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
Make sure no other process is writing to the table. Create new external table using partitioning. Insert into new table by selecting from the old table. Drop the new table (external), only table will be dropped but data will be there.
Use the ALTER TABLE ADD PARTITION statement to add a new partition to the "high" end (the point after the last existing partition). To add a partition at the beginning or in the middle of a table, use the SPLIT PARTITION clause.
Unfortunately, you cannot add/create partition in existing table which was not partitioned while creation of the table.
You can refresh Hive metastore partition information manually or automatically. You run the MSCK (metastore consistency check) Hive command: MSCK REPAIR TABLE table_name SYNC PARTITIONS every time you need to synchronize a partition with your file system. You set up partition discovery to occur periodically.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With