数仓可视化3--dws层宽表

该博客围绕大数据展开,涉及用户和商家相关的数据统计。包括用户启动、浏览、查询、关注店铺等信息,还有用户交易、投诉订单情况。同时涵盖商家浏览、日销售统计,以及广告投放和用户营销活动统计。

一、用户主题

1.1、用户启动表:

昨天是统计的一个用户启动一次,就记录一次,将启动时间变为了时间段

create external table if not exists dws_nshop.dws_nshop_ulog_launch(
  user_id string comment '用户id',
  device_num string comment '设备号',
  device_type string comment '设备类型',
  os string comment '手机系统',
  os_version string comment '手机系统版本',
  manufacturer string comment '手机制造商',
  carrier string comment '电信运营商',
  network_type string comment '网络类型',
  area_code string comment '地区编码',
  launch_count int comment '启动次数'
) partitioned by (bdp_day string)
stored as parquet
location '/data/nshop/dws/user/dws_nshop_ulog_launch/'
insert into table dws_nshop.dws_nshop_ulog_launch partition(bdp_day='20231227')
select 
distinct 
user_id,
device_num ,
device_type ,
os  ,
os_version,
manufacturer,
carrier,
network_type,
area_code,
count(1) over(partition by user_id) as launch_count 
from 
dwd_nshop.dwd_nshop_actlog_launch 
where bdp_day='20231227';

 1.2、用户浏览表

create external table if not exists dws_nshop.dws_nshop_ulog_view(
  user_id string comment '用户id',
  device_num string comment '设备号',
  device_type string comment '设备类型',
  os string comment '手机系统',
  os_version string comment '手机系统版本',
  manufacturer string comment '手机制造商',
  carrier string comment '电信运营商',
  network_type string comment '网络类型',
  area_code string comment '地区编码',
  view_count int comment '浏览次数'
) partitioned by (bdp_day string)
stored as parquet
location '/data/nshop/dws/user/dws_nshop_ulog_view/';
insert overwrite table dws_nshop.dws_nshop_ulog_view partition(bdp_day='20231227')
select 
distinct user_id ,
device_num ,
device_type ,
os ,
os_version ,
manufacturer,
carrier ,
network_type,
area_code ,
count(user_id) over(partition by user_id) view_count
from dwd_nshop.dwd_nshop_actlog_pdtview
where bdp_day="20231227";

1.3、用户查询

create external table if not exists dws_nshop.dws_nshop_ulog_search(
  user_id string comment '用户id',
  device_num string comment '设备号',
  device_type string comment '设备类型',
  os string comment '手机系统',
  os_version string comment '手机系统版本',
  manufacturer string comment '手机制造商',
  carrier string comment '电信运营商',
  network_type string comment '网络类型',
  area_code string comment '地区编码',
  search_count int comment '搜索次数'
) partitioned by (bdp_day string)
stored as parquet
location '/data/nshop/dws/user/dws_nshop_ulog_search/';
insert overwrite table dws_nshop.dws_nshop_ulog_search partition(bdp_day='20231227')
select 
distinct user_id ,
device_num ,
device_type ,
os ,
os_version ,
manufacturer,
carrier ,
network_type,
area_code ,
count(user_id) over(partition by user_id) search_count
from dwd_nshop.dwd_nshop_actlog_pdtsearch
where bdp_day="20231227";

1.4、用户关注店铺汇总表

create external table if not exists dws_nshop.dws_nshop_ulog_comment(
  user_id string comment '用户id',
  device_num string comment '设备号',
  device_type string comment '设备类型',
  os string comment '手机系统',
  os_version string comment '手机系统版本',
  manufacturer string comment '手机制造商',
  carrier string comment '电信运营商',
  network_type string comment '网络类型',
  area_code string comment '地区编码',
  comment_count int comment '用户关注次数店铺的次数',-- 不去重
  comment_target_count int comment '店铺目前有多少人关注',--去重
  ct bigint comment '产生时间'
) partitioned by (bdp_day string)
stored as parquet
location '/data/nshop/dws/user/dws_nshop_ulog_comment/';
insert overwrite table dws_nshop.dws_nshop_ulog_comment partition(bdp_day='20231227')
select 
distinct
user_id ,
device_num ,
device_type ,
os ,
os_version ,
manufacturer,
carrier ,
network_type,
area_code ,
-- 一个用户关注了这个店铺多少次
count(1) over(partition by user_id,target_id) ,
-- 一个店铺被多少人关注
count(distinct user_id) over(partition by target_id) ,
current_timestamp()
from 
dwd_nshop.dwd_actlog_product_comment
where bdp_day='20231227';

 二、用户交易信息宽表

create external table if not exists dws_nshop.dws_nshop_user_orders(
  user_id string comment '用户id',
  customer_natives string comment '所在区域',
  orders_count int comment '订单数量',
  orders_pay DECIMAL(10,1) comment '订单金额',
  orders_shipping DECIMAL(10,1) comment '订单运费金额',
  orders_district DECIMAL(10,1) comment '订单优惠金额',
  ct bigint comment '产生时间'
) partitioned by (bdp_day string)
stored as parquet
location '/data/nshop/dws/user/dws_nshop_user_orders/';
insert into table dws_nshop.dws_nshop_user_orders partition (bdp_day='20231227')
select 
distinct 
o.customer_id,
c.customer_natives,
count(1) over(partition by o.customer_id) orders_count ,
sum(o.payment_money)  over(partition by o.customer_id) orders_pay,
sum(o.shipping_money) over(partition by o.customer_id) orders_shipping,
sum(o.district_money) over(partition by o.customer_id) orders_district,
current_timestamp()
from 
dwd_nshop.dwd_nshop_orders_details  o
join 
ods_nshop.ods_02_customer c
on c.customer_id = o.customer_id
where o.bdp_day='20231227';

 三、用户投诉订单表

create external table if not exists dws_nshop.dws_nshop_user_complainant(
  user_id string comment '用户id',
  area_code string comment '地区编码',
  compl_orders_count int comment '订单数量',
  compl_orders_pay DECIMAL(10,1) comment '订单金额',
  compl_supplier_count int comment '商家数量',
  ct bigint comment '产生时间'
) partitioned by (bdp_day string)
stored as parquet
location '/data/nshop/dws/user/dws_nshop_user_complainant/';
insert into table dws_nshop.dws_nshop_user_complainant partition (bdp_day='20231227')
select 
o.customer_id,
c.customer_natives area_code,
count(1) orders_count,
sum(o.payment_money)  orders_pay,
count(distinct supplier_code) compl_supplier_count,
current_timestamp()
from 
dwd_nshop.dwd_nshop_orders_details  o
join 
ods_nshop.ods_02_customer c
on c.customer_id = o.customer_id
where o.bdp_day='20231227' and o.order_status=7
group by o.customer_id,c.customer_natives;

四、商家浏览统计表

 

create external table if not exists dws_nshop.dws_nshop_supplier_user(
  supplier_id string comment '商家id',
  supplier_type int comment '供应商类型:1.自营,2.官方 3其他',
  view_count int comment '浏览次数',
  comment_users int comment '关注人数',
  comment_area_code int comment '关注地区数量',
  ct bigint comment '产生时间'
) partitioned by (bdp_day string)
stored as parquet
location '/data/nshop/dws/supplier/dws_nshop_supplier_user/';
思路:
1、通过浏览表千方百计的跟产品表关联,产品表可以获取商家表(供应商、店铺)
2、根据商家id以及商家类型分组,统计指标

insert overwrite table dws_nshop.dws_nshop_supplier_user partition(bdp_day='20231227')
select
d.supplier_code,
d.supplier_type,
count(1) view_count,
count(distinct user_id) comment_users,
count(distinct area_code) comment_area_code,
current_timestamp()

from dwd_nshop.dwd_nshop_actlog_pdtview a
join dim_nshop.dim_pub_page  b
on a.target_id= b.page_code  and a.bdp_day='20231227'
join dim_nshop.dim_pub_product c
on b.page_target = c.product_code
join dim_nshop.dim_pub_supplier d
on c.supplier_code= d.supplier_code
group by d.supplier_code,d.supplier_type;

 五、商家日销售统计表

create external table if not exists dws_nshop.dws_nshop_supplier_sales(
  supplier_id string comment '供应商id',
  supplier_type int comment '供应商类型:1.自营,2.官方 3其他',
  sales_users int comment '购物人数',
  sales_users_area int comment '购物地区数量',
  sales_orders int comment '购物订单数',
  salaes_orders_pay DECIMAL(10,1) comment '订单金额',
  salaes_orders_district DECIMAL(10,1) comment '订单优惠金额',
  ct bigint comment '产生时间'
) partitioned by (bdp_day string)
stored as parquet
location '/data/nshop/dws/supplier/dws_nshop_supplier_sales/';
insert overwrite table dws_nshop.dws_nshop_supplier_sales partition(bdp_day='20231227')
select 
   s.supplier_code,
   s.supplier_type,
  count(distinct c.customer_id) sales_users,
  count(distinct c.customer_natives) sales_users_area,
  count(1)  sales_orders,
  sum(payment_money)  salaes_orders_pay,
  sum(district_money)  salaes_orders_district,
  current_timestamp()
  from 
dim_nshop.dim_pub_supplier   s
join 
dwd_nshop.dwd_nshop_orders_details  o
on o.supplier_code = s.supplier_code
join ods_nshop.ods_02_customer  c
on o.customer_id = c.customer_id

where o.bdp_day='20231227'
group by s.supplier_code,s.supplier_type;

 六、广告投放统计表

create external table if not exists dws_nshop.dws_nshop_release_user(
  release_sources string comment '投放渠道',
  release_category string comment '投放浏览产品分类',
  release_users int comment '投放浏览用户数',
  release_product_page int comment '投放浏览产品页面数',
  ct bigint comment '创建时间'
) partitioned by (bdp_day string)
stored as parquet
location '/data/nshop/dws/release/dws_nshop_release_user/';
insert overwrite table dws_nshop.dws_nshop_release_user partition(bdp_day='20231227')
select 
      release_sources,
      release_category,
      count(distinct customer_id) release_users,
      count(distinct release_product_page) release_product_page,
      current_timestamp()
      from dwd_nshop.dwd_nshop_releasedatas 
   where bdp_day='20231227' group by release_sources,release_category;

七、用户营销活动表

create external table if not exists dws_nshop.dws_nshop_user_release(
  user_id string comment '用户id',
  os string comment '手机系统',
  os_version string comment '手机系统版本',
  manufacturer string comment '手机制造商',
  carrier string comment '电信运营商',
  network_type string comment '网络类型',
  area_code string comment '地区编码',
  source_count int comment '投放来源数量',
  ct bigint comment '产生时间'
) partitioned by (bdp_day string)
stored as parquet
location '/data/nshop/dws/user/dws_nshop_user_release/';
insert overwrite table dws_nshop.dws_nshop_user_release partition(bdp_day='20231227')
select 
distinct 
a.customer_id,
a.os ,
a.os_version ,
a.manufacturer,
b.carrier,
b.network_type,
a.area_code ,
count(1) over (partition by a.release_sources),
current_timestamp()
from 
dwd_nshop.dwd_nshop_releasedatas a
join ods_nshop.ods_nshop_01_useractlog b
on a.customer_id = b.customer_id and a.bdp_day='20231227' and b.bdp_day='20231227';

数据仓库Data Warehouse)简称DW或DWH,是据库的一种概念上的升级,可以说是为满足新需求设计的一种新据库,而这个据库是需容纳更多的据,更加庞大的据集,从逻辑上讲数据仓库据库是没有什么区别的。为企业所有级别的决策制定过程,提供所有类型据支撑的战略集合,主要是用于据挖掘和据分析,以建立据沙盘为基础,为消灭消息孤岛和支持决策为目的而创建的。 数据仓库的应用 1.据分析、据挖掘、人工智能、机器学习、风险控制、无人驾驶。 2.据化运营、精准运营。 3.广告精准、智能投放。 随着我们从IT时代步入DT时代,据积累量也与日俱增,同时伴随着互联网的发展,越来越多的应用场景产生,传统的据处理、存储方式已经不能满足日益增长的需求。而互联网行业相比传统行业对新生事物的接受度更高、应用场景更复杂, 因此基于大数据构建的数据仓库先在互联网行业得到了尝试。 高性能高扩展的亿级电商全端实时数据仓库全实现(PC、移动、小程序) ,以热门的互联网电商实际业务应用场景为案例讲解,对电商数据仓库的常见实战指标以及难点实战指标进行了详尽讲解,具体指标包括:每日、月大盘收入报、高付费用户分析报、流量域多方位分析、营销域多方位分析、实时排行榜指标分析、用户主题分析、店铺主题时间区间分析等,据分析涵盖全端(PC、移动、小程序)应用,与互联网企业大数据技术同步,让大家能够真正学到大数据企业级数据仓库的实战经验。本课程凝聚讲师多年一线大数据企业实际项目经验,大数据企业在职架构师亲自授课,全程实操代码,带你体验真实的大数据开发过程,代码现场调试。通过本课程的学习再加上老师的答疑,你完全可以将本案例直接应用于企业。本套课程可以满足世面上绝大多大数据企业级的数据仓库业务场景,全部代码可以直接部署企业,支撑亿级并发据分析。该项目代码也是具有极高的商业价值的,大家可以根据自己的业务进行修改,便可以使用。本课程包含的技术:  开发工具为:IDEA、WebStorm Flink1.9.0 Greenplum5.0.0 Hadoop2.6.0 Hbase1.0.0 Kafka2.1.0 Hive1.1.0 HDFS、MapReduce Redis、Flume Sqoop、Zookeeper MyBatis、EhCache SpringBoot2.0.2.RELEASE SpringCloud Finchley.RELEASE Binlog、Canal MySQL、MyCat Vue.js、Nodejs Highcharts课程亮点: 1.与企业对接、真实工业界产品  2.支持海量据的分析 3.支持全端实时据分析 4.通用数据仓库解决方案 5.据库实时同步解决方案 6.主流微服务后端系统 7.电商数据仓库实战指标 8.实时加离线多方位分析 9.互联网大数据企业热门技术栈 10.分布式据库存储解决方案 11.涵盖主流前端技术VUE+jQuery+Ajax+NodeJS 12.大数据热门技术Flink新版本13.集成SpringCloud实现统一整合方案 14.全程代码实操,提供全部代码和资料 15.提供答疑和提供企业技术方案咨询企业一线架构师讲授,代码企业直接复用,提供企业解决方案。  版权归作者所有,盗版将进行法律维权。 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值