没有合适的资源?快使用搜索试试~ 我知道了~
hive分区表分通表建表语句详解和例子
需积分: 49 28 下载量 87 浏览量
2018-11-01
10:31:55
上传
评论 1
收藏 10KB TXT 举报
温馨提示
试读
9页
详细描述了hive分桶表,分区表的创建,附带详细建表语句,包含一级静态分区,二级静态分区,一级动态分区,二级动态分区,分区的查询,删除,添加,数据的导入
资源推荐
资源详情
资源评论
=======================================================================================================================================================
静态分区表
=======================================================================================================================================================
一级分区的静态分区表
create table my_partitioner1(
id bigint,
name string,
time date,
love varchar(50))
partitioned by(sex string)
row format delimited fields terminated by '\t'
二级分区的静态分区表
create table my_partitioner3(
id bigint,
name string,
time date,
interest array<string>)
partitioned by(sex string,country string)
row format delimited fields terminated by '\t'
collection items terminated by ','
分区数据
1 wd 2018-10-25 睡觉
2 zam 2018-10-26 吃
3 dong 2018-10-25 玩游戏
1 zam 2018-10-25 睡觉,吃,玩游戏
静态分区表
=======================================================================================================================================================
一级分区的静态分区表
create table my_partitioner1(
id bigint,
name string,
time date,
love varchar(50))
partitioned by(sex string)
row format delimited fields terminated by '\t'
二级分区的静态分区表
create table my_partitioner3(
id bigint,
name string,
time date,
interest array<string>)
partitioned by(sex string,country string)
row format delimited fields terminated by '\t'
collection items terminated by ','
分区数据
1 wd 2018-10-25 睡觉
2 zam 2018-10-26 吃
3 dong 2018-10-25 玩游戏
1 zam 2018-10-25 睡觉,吃,玩游戏
2 zam 2018-10-26 吃,点豆豆,上天
3 wd 2018-10-25 玩游戏,睡觉
1.数据加载到表
由本地文件插入
load data [local] inpath '/root/my_partitioner3.txt into table my_partitioner4 partition(sex='woman',country='usa');
由子查询导入,需要指定分区
insert into my_partitioner5 partition(sex='man',country='usa') select id,name,time,interest from my_partitioner4 where sex='man' andcountry='usa';
文件直接导入hdfs制定区域
再刷新元数据信息
msck repair table order_created_partition;
2.查询时间大于10-25 的interest
select interest from my_partitioner4 where time>'2018-10-25';
3.查询某个分区的数据
select * from my_partitioner4 where sex='woman';
select * from my_partitioner4 where sex='woman' and country='china';
4.添加分区,只能在当前级数下进行分区,数目必须和其一致
alter table my_partitioner4 add partition (sex='woman',country='china');
5.删除分区
alter table my_partitioner4 drop partition(sex='woman',country='china');
6.显示已有分区
show partitions my_partitioner4;
7.删除表数据(删除所有数据,保留表结构)
truncate table d_patition1;
3 wd 2018-10-25 玩游戏,睡觉
1.数据加载到表
由本地文件插入
load data [local] inpath '/root/my_partitioner3.txt into table my_partitioner4 partition(sex='woman',country='usa');
由子查询导入,需要指定分区
insert into my_partitioner5 partition(sex='man',country='usa') select id,name,time,interest from my_partitioner4 where sex='man' andcountry='usa';
文件直接导入hdfs制定区域
再刷新元数据信息
msck repair table order_created_partition;
2.查询时间大于10-25 的interest
select interest from my_partitioner4 where time>'2018-10-25';
3.查询某个分区的数据
select * from my_partitioner4 where sex='woman';
select * from my_partitioner4 where sex='woman' and country='china';
4.添加分区,只能在当前级数下进行分区,数目必须和其一致
alter table my_partitioner4 add partition (sex='woman',country='china');
5.删除分区
alter table my_partitioner4 drop partition(sex='woman',country='china');
6.显示已有分区
show partitions my_partitioner4;
7.删除表数据(删除所有数据,保留表结构)
truncate table d_patition1;
剩余8页未读,继续阅读
资源评论
大耳朵丶猴
- 粉丝: 1
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功