一、为啥分区
hive 为了避免全表查询,从而引进分区,将数据按目录进行划分,减少不必要的查询,从而提高效率
二、hive的分区和mysql分区的区别
mysql的分区字段用的是表内字段,hive的分区字段采用表外字段,也就是使用伪字段,分区字段在创建表的时候指定
分区的关键字:partitioned by(字段)
三、静态分区练习
create table if not exists u1(
id int,
name string,
age int
)
partitioned by(dt string)
row format delimited fields terminated by ' '
stored as textfile
;
1 xm1 16
2 xm2 18
3 xm3 22
11 xh1 26
22 xh2 28
33 xh3 30
load data local inpath '/home/u1' into table u1 partition(dt="2018-10-14");
load data local inpath '/home/u115' into table u1 partition(dt="2018-10-15");
四、二级分区
create table if not exists u2(
id int,
nam