SparkSQL电商用户画像(六)之用户画像开发(订单宽表)      

 

7.3 用户画像开发--订单表宽表

--订单宽表模型create database if not exists gdm;create  table if not exists gdm.itcast_gdm_order(

order_id   string,--订单IDorder_no   string,--订单号order_date string,--订单日期user_id string,--用户IDuser_name string,--登录名order_money double,--订单金额order_type string,--订单类型order_status       string,--订单状态pay_status string,--支付状态pay_type string,--支付方式  1、在线支付,2、货到付款order_source       string,--订单来源consignee string,--收货人姓名area_id string,--收货人地址IDarea_name string,--地址ID对应的地址段(粒度到县)address string,--收货人地址(手工填写的地址)mobile string,--收货人手机号telphone string,--收货人电话coupon_id bigint,--使用代金券IDcoupon_money double,--使用代金券金额carriage_money double,--运费create_time timestamp,--创建时间update_time timestamp,--更新时间dw_date timestamp) partitioned by (dt string);
--订单主要信息表BDM层create database if not exists bdm;create external table if not exists bdm.itcast_bdm_order(

order_id string, --订单IDorder_no string, --订单号order_date string, --订单日期user_id  string, --用户IDuser_name string, --登录名order_money double, --订单金额order_type string, --订单类型order_status string,       --订单状态pay_status string, --支付状态pay_type string, --支付方式  1、在线支付,2、货到付款order_source string,       --订单来源update_time timestamp, --订单更新时间dw_date timestamp) partitioned by (dt string)

row format delimited fields terminated by ','lines terminated by '\n';alter table bdm.itcast_bdm_order add partition (dt='2017-01-01') location '/business/itcast_bdm_order/2017-01-01';

hdfs dfs -put fdm_order.txt /business/itcast_bdm_order/2017-01-01
--订单主要信息表FDM层create database if not exists fdm;create  table if not exists fdm.itcast_fdm_order(

order_id string, --订单IDorder_no string, --订单号order_date string, --订单日期user_id  string, --用户IDuser_name string, --登录名order_money double, --订单金额order_type string, --订单类型order_status string,       --订单状态pay_status string, --支付状态pay_type string, --支付方式  1、在线支付,2、货到付款order_source string,       --订单来源update_time timestamp, --订单更新时间dw_date timestamp) partitioned by (dt string); 

--加载数据insert overwrite table fdm.itcast_fdm_order partition(dt='2017-01-01')selectt.order_id, --订单IDt.order_no, --订单号t.order_date,       --订单日期t.user_id, --用户IDt.user_name,       --登录名t.order_money, --订单金额t.order_type,       --订单类型t.order_status,       --订单状态t.pay_status,       --支付状态t.pay_type, --支付方式t.order_source,       --订单来源t.update_time timestamp,--订单更新时间from_unixtime(unix_timestamp())  dw_datefrom bdm.itcast_bdm_order t where dt='2017-01-01';
-------订单详细信息表BDM层----------------create database if not exists bdm;create external table if not exists bdm.itcast_bdm_order_desc(

order_id string, --订单IDorder_no string, --订单号consignee string, --收货人姓名area_id string, --收货人地址IDarea_name string, --地址ID对应的地址段address string, --收货人地址mobile string, --收货人手机号telphone string, --收货人电话coupon_id bigint, --使用代金券IDcoupon_money double, --使用代金券金额carriage_money double, --运费create_time timestamp, --创建时间update_time timestamp, --更新时间dw_date timestamp)partitioned by (dt string)

row format delimited fields terminated by ',';alter table bdm.itcast_bdm_order_desc add partition (dt='2017-01-01') location '/business/itcast_bdm_order_desc/2017-01-01';

hdfs dfs -put itcast_bdm_order_desc.txt /business/itcast_bdm_order_desc/2017-01-01
-----订单主要信息表FDM层create database if not exists fdm;create table if not exists fdm.itcast_fdm_order_desc(

order_id string, --订单IDorder_no string, --订单号consignee string, --收货人姓名area_id string, --收货人地址IDarea_name string, --地址ID对应的地址段address string, --收货人地址mobile string, --收货人手机号telphone string, --收货人电话coupon_id bigint, --使用代金券IDcoupon_money double, --使用代金券金额carriage_money double, --运费create_time timestamp, --创建时间update_time timestamp, --更新时间dw_date timestamp) partitioned by (dt string); 

------加载数据insert overwrite table fdm.itcast_fdm_order_desc partition(dt='2017-01-01')selectt.order_id, --订单IDt.order_no, --订单号t.consignee,       --收货人姓名t.area_id, --收货人地址IDt.area_name,       --地址ID对应的地址段t.address, --收货人地址t.mobile, --收货人手机号t.telphone, --收货人电话t.coupon_id,       --使用代金券IDt.coupon_money, --使用代金券金额t.carriage_money,       --运费t.create_time,       --创建时间t.update_time,       --更新时间from_unixtime(unix_timestamp())  dw_datefrom bdm.itcast_bdm_order_desc t where dt='2017-01-01';
--------订单宽表模型表GDMcreate database if not exists gdm;create external table if not exists gdm.itcast_gdm_order(

order_id string, --订单IDorder_no string, --订单号order_date string, --订单日期user_id string, --用户IDuser_name string, --登录名order_money double, --订单金额order_type string, --订单类型order_status string,--订单状态pay_status string, --支付状态pay_type string, --支付方式  1、在线支付,2、货到付款order_source string,--订单来源consignee string, --收货人姓名area_id string, --收货人地址IDarea_name string, --地址ID对应的地址段(粒度到县)address string, --收货人地址(手工填写的地址)mobile string, --收货人手机号telphone string, --收货人电话coupon_id bigint, --使用代金券IDcoupon_money double,--使用代金券金额carriage_money double,--运费create_time timestamp,--创建时间update_time timestamp,--更新时间dw_date timestamp) partitioned by (dt string); 

---加载数据生成订单宽表insert overwrite table gdm.itcast_gdm_order partition(dt='2017-01-01')selecta.order_id, --订单IDa.order_no, --订单号a.order_date,       --订单日期a.user_id, --用户IDa.user_name,       --用户名a.order_money, --订单金额a.order_type,       --订单类型a.order_status,    --订单状态a.pay_status,       --支付类型a.pay_type, --支付方式a.order_source, --订单来源b.consignee,       --收货人姓名b.area_id, --收货人地址IDb.area_name,       --地址ID对应的地址段b.address, --收货人地址b.mobile,          --收货人手机号b.telphone,         --收货人电话b.coupon_id,       --使用代金券IDb.coupon_money,   --使用代金券金额b.carriage_money,  --运费b.create_time,     --创建时间b.update_time,     --更新时间from_unixtime(unix_timestamp()) dw_datefrom (select *  from fdm.itcast_fdm_order where dt='2017-01-01') ajoin (select * from fdm.itcast_fdm_order_desc where dt='2017-01-01') b on a.order_id=b.order_id;