hive partition 分区详解二

hive建分区表

create external table if not exists cheap_hotel_user(device string, booking_freq int, book_price string)
partitioned by (day string)
row format delimited fields terminated by '\t'
location '/data/output/search/stage/daily/cheap_hotel_user'

注意的是partition需要在row formate之前指定


添加分区

ALTER TABLE table_name ADD PARTITION (partCol = 'value1') location 'loc1';

ALTER TABLE table_name ADD IF NOT EXISTS PARTITION (dt='20130101') LOCATION '/user/hadoop/warehouse/table_name/dt=20130101'; //一次添加一个分区

ALTER TABLE page_view ADD PARTITION (dt='2008-09-01', country='jp') location '/path/to/us/part080901 PARTITION (dt='2008-09-01', country='jp') location '/path/to/us/part080901';  //一次添加多个分区


删除分区

ALTER TABLE login DROP IF EXISTS PARTITION (dt='2008-09-01');
ALTER TABLE page_view DROP IF EXISTS PARTITION (dt='2008-09-01', country='jp');

修改分区
ALTER TABLE table_name PARTITION (dt='2008-08-08') SET LOCATION "new location";
ALTER TABLE table_name PARTITION (dt='2008-08-08') RENAME TO PARTITION (dt='20080808’);

你可能感兴趣的:(hive)