分区表:分区是目录。
------------------
//创建分区表
CREATE TABLE custs
(
id int,
name string ,
age int
)
PARTITIONED BY (prov string, city string)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
STORED AS TEXTFILE;
//添加分区
alter table custs add PARTITION (prov='hebei', city='baoding') PARTITION (prov='hebei', city='shijiazhuang');
//查看分区
SHOW PARTITIONS custs;
//删除分区
alter table custs drop partition partition(prov='hebei',city='shijizhuang') ;
//加载数据到分区
load data local inpath '/home/centos/cust.txt' into table custs partition(prov='hebei',city='baoding') ;
//按照分区查询
select * from custs where city = 'baoding' ;
------------------
//创建分区表
CREATE TABLE custs
(
id int,
name string ,
age int
)
PARTITIONED BY (prov string, city string)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
STORED AS TEXTFILE;
//添加分区
alter table custs add PARTITION (prov='hebei', city='baoding') PARTITION (prov='hebei', city='shijiazhuang');
//查看分区
SHOW PARTITIONS custs;
//删除分区
alter table custs drop partition partition(prov='hebei',city='shijizhuang') ;
//加载数据到分区
load data local inpath '/home/centos/cust.txt' into table custs partition(prov='hebei',city='baoding') ;
//按照分区查询
select * from custs where city = 'baoding' ;