HiveSQL分区的作用及创建分区表案例演示(图解)_hive 动态分区sql



2.2上传(6个)源文件到该hive表的HDFS路径下


![](https://img-blog.csdnimg.cn/direct/c0eb55c8031846318238ae7d094d863f.png)


##### 3.查询数据



select * from t_all_hero;


![](https://img-blog.csdnimg.cn/direct/9211abf933aa4a01881d8b1708b554e6.png)


 3.1查询出所有的archer数据



select * from t_all_hero where role_main=‘archer’;



问:虽然我们实现了需求, 但是需要进行全表扫描, 如何精准的获取到我们想要的数据呢?



答:可以采用分区表的思路来管理, 把各个职业的数据放到不同的文件夹中即可


##### 4.创建分区数据表



– 1. 创建分区表, 指定分区字段.
create table t_all_hero_part(
id int comment ‘ID’,
name string comment ‘英雄’,
hp_max int comment ‘最大生命’,
mp_max int comment ‘最大法力’,
attack_max int comment ‘最高物攻’,
defense_max int comment ‘最大物防’,
attack_range string comment ‘攻击范围’,
role_main string comment ‘主要定位’,
role_assist string comment ‘次要定位’
) comment ‘角色表’
partitioned by (role string comment ‘角色字段-充当分区字段’) – 核心细节: 分区字段必须是表中没有的字段.
row format delimited fields terminated by ‘\t’;



注意:分区字段必须是新的字段,表中没有的字段哦


##### 5.添加数据


###### 5.1添加方式1:静态分区(需要指定分区字段和值)



lo

  • 10
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值