hive動態分區注意事項

注意:插入數據的時候,字段順序需與建立分區表時的順序一致。node

#################建立分區表orm

drop table if exists default.rpt_customer_coupon_details_partition;ip

CREATE TABLE default.rpt_customer_coupon_details_partition (
  `id` int,
  `cname` string,
  `cphone` string,
  `ccity` string,
  `couponid` int,
  `couponname` string,
  `accity` string,
  `ctype` int,
  `couponvalue` double ,
  `duration` string ,
  `pagename` string ,
  `expired_at` string ,
  `status` int ,
  `minCost` double ,
  `maxDiscount` double ,
  `minPay` double ,
  `created_at` string ,
  `updated_at` string,
  `source` string ,
  `actionname` string ,
  `carprice` double,
  `taxiprice` double,
  `ticketprice` double,
  `buspoolprice` double
)
comment 'rpt_customer_coupon_details'
partitioned by (year string,month string,date_id string)
row format delimited fields terminated by '\t'
stored as textfile;ci

########設置動態分區
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
set hive.exec.max.dynamic.partitions.pernode=10000;
set hive.exec.max.dynamic.partitions=10000;
set hive.exec.max.created.files=150000; 
set dfs.datanode.max.xcievers=8192;rem


######向分區表插入數據
insert into default.rpt_customer_coupon_details_partition
partition (year,month,date_id)
select 
a.id,
b.`name` cname,
b.phone cphone,
a.city ccity,
a.coupon_id couponid,
c.`name` couponname,
ac.city accity,
a.type AS ctype ,
a.`value` couponvalue,
c.duration,
g.`name` pagename,
a.expire_at expired_at,
a.status,
c.minCost,
c.maxDiscount,
c.minPay,
a.created_at,
a.updated_at,
a.source,
ac.title actionname,
nvl((case when r.status=1 then nvl(price,0) else 0 end),0) carprice,
nvl((case when r.status=2 then nvl(price,0) else 0 end),0) taxiprice,
nvl((case when r.status=3 then nvl(price,0) else 0 end),0) ticketprice,
nvl((case when r.status=4 then nvl(price,0) else 0 end),0) buspoolprice,
substr(to_date(a.created_at),1,4) year,
substr(to_date(a.created_at),1,7) month,
cast(to_date(a.created_at) as string) date_id
from 
(select 
x.id,
x.customer_id,
x.coupon_id,
x.giftpack_id,
x.action_id,
x.source,
x.type,
x.source_type,
x.source_id,
x.status,
x.created_at,
x.updated_at,
x.city,
x.value,
x.remark,
x.expire_at 
from default.fct_customer_coupon x 
) a 
LEFT JOIN default.dim_customer b on a.customer_id= b.id
LEFT JOIN default.dim_coupon c on a.coupon_id=c.id
LEFT JOIN default.dim_giftpack g on a.giftpack_id=g.id 
LEFT JOIN default.dim_action ac on a.action_id=ac.id 
LEFT JOIN (
     SELECT 
           p.coupon_id,
           p.price,
           p.status
     from default.fct_order_payment_deduction p 
) r on a.id=r.coupon_id
;string

相關文章
相關標籤/搜索