hive分区表创建及使用

hive分区表创建及使用

1.创建分区表

**注意:**分区字段不能出现在普通字段里面 对于分区表来说,分区字段使用跟普通字段一样

drop table s_ssd_taobao_pc2020050700001_result_s;
create table s_ssd_taobao_pc2020050700001_result_s(
    uuid         string comment 'uuid',
    phone        string comment '手机号',
    name         string comment '姓名',
    nickname     string comment '昵称',
    province     string comment '省份',
    city         string comment '城市',
    district     string comment '区县',
    address      string comment '地址',
    shop_name    string comment '店铺名称',
    order_id     string comment '订单id',
    order_date   string comment '订单日期',
    time         string comment '时间'
)
partitioned by (part string)
row format delimited
fields terminated by '\001';

2.添加分区

alter table t_ai_taobao_pc2020050700001_result_s add partition(part='par01');
alter table t_ai_taobao_pc2020050700001_result_s add partition(part='par02');
alter table t_ai_taobao_pc2020050700001_result_s add partition(part='par03');

3.查询分区数

show partitions t_ai_taobao_pc2020050700001_result_s;

4.指定分区插入数据

insert into table t_ai_taobao_pc2020050700001_result_s partition(part='par01')
select * from t_ai_taobao_pc2020050700001_result order by uuid asc limit 10000000

5.指定分区查询数据

select * from t_ai_taobao_pc2020050700001_result_s where part='par01' order by uuid desc limit 10;

你可能感兴趣的:(hive分区表创建及使用)