我是靠谱客的博主 强健日记本,这篇文章主要介绍hive分区表操作,现在分享给大家,希望可以做个参考。

分区表的操作
在hive中,可以把大的数据,按照每月,或者天进行切分成一个个的小的文件,存放在不同的文件夹中

创建分区表语法

create table score(s_id string,c_id string,s_score int) partitioned by (month string) row format delimited fields terminated by ‘t’;

创建外部分区表,并指定文件数据存放目录

create table score(s_id string,c_id string,s_score int) partitioned by (month string) row format delimited fields terminated by ‘t’ location ‘/scoredatas’;
上传文件
hdfs dfs -put score.csv /scoredatas/month=202104
进行表的修复(建立表与数据文件之间的一个关系映射)
msck repair table score;

创建一个表带多个分区

create table score2(s_id string,c_id string,s_sorce int) partitioned by (year strint,month string,day string) row format delimited fields terminated by ‘t’;

加载数据到分区表中

load data local inpath ‘/export/servers/socre.csv’ into path score partition (month=‘202104’);

加载数据到多分区表中

load data local inpath ‘/export/servers/socre.csv’ into path score partition (year=‘2021’,month=‘04’,day=‘01’);

多分区表查询

select * from score where month=‘02’;

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

select * from score where month=‘202103’ union all select * from score where month=‘202104’;

查看分区

show partition score;

添加一个分区

alter table score add partition(month=‘202104’);

删除分区

alter table score drop partition(month=‘202104’);

最后

以上就是强健日记本最近收集整理的关于hive分区表操作的全部内容,更多相关hive分区表操作内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(100)

评论列表共有 0 条评论

立即
投稿
返回
顶部