订单分析地域、分类维度分析业务开发

2 订单分析地域、分类维度分析业务开发

2.1 需求分析

集团总公司分为很多的分公司(销售事业部)
在这里插入图片描述
为了公司的经营需要,公司需要定期检查各个分公司的经营指标完成情况,运营部门提出数据分析需求:

  • 交易金额
  • 交易笔数
  • 微信交易笔数
  • 支付宝交易笔数
    通过以上指标数据,公司的运营人员能够了解到各个分公司的经营情况,在出现经营问题时,能够及时发现,并根据问题,去寻找问题原因。
    在这里插入图片描述
    维度如下:
  • 商品分类
  • 行政区域

要求:最终可以根据不同大区、不同城市、不能分类级别查询交易数据,也就是要求支持不同维度的组合查询。
在这里插入图片描述

2.2 创建 ads 层数据表

-- 创建ads(数据集市层)订单分析表
DROP TABLE IF EXISTS `itcast_ads`.`ads_trade_order`;

CREATE TABLE `itcast_ads`.`ads_trade_order`(
`orgtype` bigint, 
`orgid` bigint, 
`cattype` bigint, 
`catid` bigint, 
`paytype` bigint, 
`ordercount` bigint, 
`goodsprice` double)
PARTITIONED BY (`dt` string)
STORED AS PARQUET;

`orgtype`   区域类型 
`orgid`     区域类型ID 
`cattype` 	品类 
`catid`     品类ID
`paytype   支付方式 
`ordercount` 订单总数 
`goodsprice` 订单金额

2.3 创建 dw 层数据表

该层主要创建维度表与事实表。为了便于识别,维度表增加 dim_ 前缀。事实表增加 fact_ 前缀

  • fact_orders
-- 创建dw层订单事实表
DROP TABLE IF EXISTS `itcast_dw`.`fact_orders`;

CREATE TABLE `itcast_dw`.`fact_orders`(
`orderid` bigint, 
`orderno` string, 
`userid` bigint, 
`orderstatus` bigint, 
`goodsmoney` double, 
`delivertype` bigint, 
`delivermoney` double, 
`totalmoney` double, 
`realtotalmoney` double, 
`paytype` bigint, 
`ispay` bigint, 
`areaid` bigint, 
`areaidpath` string, 
`orderscore` bigint, 
`isinvoice` bigint, 
`invoiceclient` string, 
`orderremarks` string, 
`ordersrc` bigint, 
`needpay` double, 
`isrefund` bigint, 
`isclosed` bigint, 
`receivetime` string, 
`deliverytime` string, 
`tradeno` string, 
`createtime` string, 
`commissionfee` double, 
`scoremoney` double, 
`usescore` bigint, 
`noticedeliver` bigint, 
`lockcashmoney` double, 
`paytime` string, 
`isbatch` bigint, 
`totalpayfee` bigint)
partitioned by (dt string)
STORED AS PARQUET;
  • dim_goods
--  dw层商品维度表,通过拉链表已经创建
  • dim_goods_cats
-- 创建dw层商品分类维度表
DROP TABLE IF EXISTS `itcast_dw`.`dim_goods_cats`;

CREATE TABLE `itcast_dw`.`dim_goods_cats`(
`catid` bigint, 
`catname` string,
`parentid` bigint, 
`isshow` bigint, 
`isfloor` bigint, 
`createtime` bigint)
partitioned by (dt string,catLevel bigint)
STORED AS PARQUET;
  • dim_org
DROP TABLE IF EXISTS `itcast_dw`.`dim_org`;

CREATE TABLE `itcast_dw`.`dim_org`(
`orgId` bigint, 
`orgname` string,
`parentId` bigint, 
`orglevele` bigint, 
`managercode` string, 
`createtime` string, 
`updatetime` string, 
`orgtype` bigint)
PARTITIONED BY (`dt` string)
STORED AS PARQUET;
  • dim_shops
-- 创建dw层商铺维度表
DROP TABLE IF EXISTS `itcast_dw`.`dim_shops`;

CREATE TABLE `itcast_dw`.`dim_shops`(
  `shopid` bigint, 
  `areaid` bigint, 
  `shopname` string, 
  `servicestarttime` bigint, 
  `serviceendtime` bigint, 
  `shopstatus` bigint, 
  `bdcode` string)
  partitioned by (dt string)
STORED AS PARQUET;

2.4 ods层数据至dw层

  • fact_orders
    • 导入ods层 2019年09月09日的订单数据到 20190908 分区
    • 导入数据后使用 hive/beeline确认数据是否正确映射
INSERT OVERWRITE TABLE `itcast_dw`.`fact_orders` PARTITION (dt='20190909')
SELECT
  orderid,
  orderno,
  userid,
  orderstatus,
  goodsmoney,
  delivertype,
  delivermoney,
  totalmoney,
  realtotalmoney,
  paytype,
  ispay,
  areaid,
  areaidpath,
  orderscore,
  isinvoice,
  invoiceclient,
  orderremarks,
  ordersrc,
  needpay,
  isrefund,
  isclosed,
  receivetime,
  deliverytime,
  tradeno,
  createtime,
  commissionfee,
  scoremoney,
  usescore,
  noticedeliver,
  lockcashmoney,
  paytime,
  isbatch,
  totalpayfee
FROM `itcast_ods`
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值