首页 > 代码库 > Hive分区

Hive分区

1、查看分区

Hive> show partitions  table_name;

dt=20101101

dt=20101102

....

Time taken: 0.140 seconds, Fetched: 10 row(s)

2、  hive>desc  tb  partition(dt=20170612) 

3.hive>  desc extended  tb  partition(dt=20170612) 

可以用这个命令查看有时候建立分区是在特定指定location的。

4、建立分区表

CREATE EXTERNAL TABLE seed_my (col MAP<STRING, STRING>) partitioned by (dt string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘,‘  COLLECTION ITEMS TERMINATED BY ‘\t‘ MAP KEYS TERMINATED BY ‘|‘ STORED AS INPUTFORMAT "org.apache.hadoop.mapred.TextInputFormat" OUTPUTFORMAT "org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat" LOCATION ‘s3://up/seed/myhome‘; 

 

5、添加分区

ALTER TABLE table_name ADD PARTITION (dt= ‘$dt‘) location ‘$dt‘;

ALTER TABLE table_name ADD IF NOT EXISTS PARTITION (dt=‘$dt‘) LOCATION ‘/sss/$dt‘; //一次添加一个分区

ALTER TABLE table_name ADD PARTITION (dt=‘$dt‘, hour=‘$hour‘) location ‘/path/$dt/$hour  PARTITION (dt=‘$dt‘,  hour=‘$hour‘) location ‘/path/$dt/$hour‘;  //一次添加多个分区

 

6\删除分区

ALTER TABLE table_name DROP IF EXISTS PARTITION (dt=‘dt‘);
ALTER TABLE table_name DROP IF EXISTS PARTITION (dt=‘dt‘, hour=‘$hour‘);


修改分区
ALTER TABLE table_name PARTITION (dt=‘$dt‘) SET LOCATION "$path";
ALTER TABLE table_name PARTITION (dt=‘$dt‘) RENAME TO PARTITION (dt=‘$dt_yyyymmdd’);

 
 
<style></style>

Hive分区