Can I increase number of buckets after table creation in hive?

207 Views Asked by At

In hive, once the table is created with n buckets. Is their any way to increase number of buckets?

1

There are 1 best solutions below

0
On

Buckets are physical folders so we cant do it easily. You need to recreate the table with new structure.
step 1 - create a table with new structure.

CREATE TABLE  [db_name.]newtable (...)
[CLUSTERED BY (col_name, col_name, ...) INTO num_buckets BUCKETS;

step 2 - reload newtable from original.

insert into newtable select * from mytable;

step 3 - drop original table and rename new table to original.

drop table mytable;
alter table newtable rename to mytable;