longgb246的博客

基本命令

1、设置动态分区

1
2
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;

2、设置最大动态分区

1
2
set hive.exec.max.dynamic.partitions=2000;
set hive.exec.max.dynamic.partitions.pernode=2000;

3、创建动态分区表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
CREATE TABLE IF NOT EXISTS dev.dev_allocation_sale_data
( org_dc_id string,
sale_ord_det_id string,
sale_ord_id string,
parent_sale_ord_id string,
item_sku_id string, -- skuid
sale_qtty int, -- 销售数量
sale_ord_tm string, -- 销售订单订购时间
sale_ord_type string, -- 订单配送类型
sale_ord_white_flag string, -- 是否包括白名单
item_third_cate_cd string, --sku所属三级分类
item_second_cate_cd string, --sku所属二级分类
shelves_dt string, --上架日期
shelves_tm string --上架时间
)
PARTITIONED by (date_s string,dc_id int);

4、插入动态分区表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
insert overwrite table dev.dev_allocation_sale_data partition(date_s,dc_id)
select
a.org_dc_id,
case when b.sale_ord_id is not null then 'rdc'
when c.sale_ord_id is not null then 'fdc_rdc' when d.sale_ord_id is not null then 'fdc' else 'other' end,
d.white_flag,
a.item_third_cate_cd,
a.item_second_cate_cd,
a.shelves_dt,
a.shelves_tm,
a.dt as date_s,
a.dc_id
from
dev.tmp_allocation_order_data_mid01 a

5、取出hive数据

1
2
INSERT OVERWRITE LOCAL DIRECTORY '/home/cmo_ipc/Allocation_shell/datasets/sku_datasets'
select * from dev.dev_allocation_fdc_data;

动态分区

http://blog.csdn.net/kntao/article/details/38683645

http://blog.csdn.net/chenyi8888/article/details/8236726

坚持原创技术分享,您的支持将鼓励我继续创作!