首页
学习
活动
专区
圈层
工具
发布

大数据-Hive分区表

1. Hive 表操作

1.4. 分区表

在大数据中,最常用的一种思想就是分治,我们可以把大的文件切割划分成一个个的小的文件,这样每次操作一个小的 文件就会很容易了,同样的道理,在hive当中也是支持这种思想的,就是我们可以把大的数据,按照每天,或者每小时 进行切分成一个个的小的文件,这样去操作小的文件就会容易得多了

创建分区表语法

代码语言:javascript
复制
create table score(s_id string,c_id string, s_score int) partitioned by (month string) row format ** 

创建一个表带多个分区

代码语言:javascript
复制
create table score2 (s_id string,c_id string, s_score int) partitioned by ** 

加载数据到分区表中

代码语言:javascript
复制
load data local inpath '/export/servers/hivedatas/score.csv' into table score partition **

加载数据到多分区表中

代码语言:javascript
复制
load data local inpath '/export/servers/hivedatas/score.csv' into table score2 partition **

多分区表联合查询(使用 union all )

代码语言:javascript
复制
select * from score where month = '201806' union all select * from score where month = '201806';

查看分区

代码语言:javascript
复制
show partitions score;

添加一个分区

代码语言:javascript
复制
alter table score add partition(month='201805');

删除分区

代码语言:javascript
复制
alter table score drop partition(month = '201806');
举报
领券