hive分区

hive分区

1.在任意位置建立一个文件夹

这里以在home/bigdata下建立一个hivedata

mkdir -p /home/bigdata/hivedata

2.根据表来随便写几个数据

这里以下面建表的样板为准

用下面的数据建一个名叫stu.txt的文件

1,xiaoming,nan
2,xiaohong,nv
3,xiaowang,nan

把这个文件放到上面的那个文件夹里

上传数据到hdfs

hadoop fs -mkdir /home/hive(要一级一级创建)
hadoop fs -put /home/bigdata/hivedata(stu.txt文件所在的文件夹) /home/hive(上面刚刚创建的文件夹地址)

3.创建外部表

create external table if not exists t1(id bigint,name string,age int,sex string)
partitioned by (year int,month int,day int)
row format delimited fields terminated by ','
stored as textfile;

4.创建内部表

create table if not exists t2(id bigint,name string,age int,sex string)
partitioned by (year int,month int,day int)
row format delimited fields terminated by ','
stored as textfile;

5.分区操作

分区下分子区

alter table t1 add partition(year=2017,month=07,day=28);

查看分区

show partitions t1;

从hdfs添加数据 会自动创建分区

load data inpath '/home/hive/hivedata' into table t1 partition(year=2017,month=07,day=28);

你可能感兴趣的:(hive分区)