离线数仓——(广告业务需求分析,广告业务ODS层建表及数据加载,广告业务DWD层建表及数据加载,广告点击次数分析,点击率购买率分析,广告效果分析)

广告业务需求分析

  1. 用户事件日志数据如下所示:

    {
    	"lagou_event": [{
    		"name": "goods_detail_loading",
    		"json": {
    			"entry": "3",
    			"goodsid": "0",
    			"loading_time": "80",
    			"action": "4",
    			"staytime": "68",
    			"showtype": "4"
    		},
    		"time": 1596225273755
    	}, {
    		"name": "loading",
    		"json": {
    			"loading_time": "18",
    			"action": "1",
    			"loading_type": "2",
    			"type": "3"
    		},
    		"time": 1596231657803
    	}, {
    		"name": "ad",
    		"json": {
    			"duration": "17",
    			"ad_action": "0",
    			"shop_id": "786",
    			"event_type": "ad",
    			"ad_type": "4",
    			"show_style": "1",
    			"product_id": "2772",
    			"place": "placeindex_left",
    			"sort": "0"
    		},
    		"time": 1596278404415
    	}, {
    		"name": "favorites",
    		"json": {
    			"course_id": 0,
    			"id": 0,
    			"userid": 0
    		},
    		"time": 1596239532527
    	}, {
    		"name": "praise",
    		"json": {
    			"id": 2,
    			"type": 3,
    			"add_time": "1596258672095",
    			"userid": 8,
    			"target": 6
    		},
    		"time": 1596274343507
    	}],
    	"attr": {
    		"area": "拉萨",
    		"uid": "2F10092A86",
    		"app_v": "1.1.12",
    		"event_type": "common",
    		"device_id": "1FB872-9A10086",
    		"os_type": "4.1",
    		"channel": "KS",
    		"language": "chinese",
    		"brand": "xiaomi-2"
    	}
    }
    
  2. 用户事件日志数据中的信息包括:

    1. 商品详情页加载:goods_detail_loading
    2. 商品列表:loading
    3. 消息通知:notification
    4. 商品评论:comment
    5. 收藏:favorites
    6. 点赞:praise
    7. 广告:ad
      1. action。用户行为;0 曝光;1 曝光后点击;2 购买
      2. duration。停留时长
      3. shop_id。商家id
      4. event_type。“ad”
      5. ad_type。格式类型;1 JPG;2 PNG;3 GIF;4 SWF
      6. show_style。显示风格,0 静态图;1 动态图
      7. product_id。产品id
      8. place。广告位置;首页=1,左侧=2,右侧=3,列表页=4
      9. sort。排序位置

广告业务需求指标:

  1. 点击次数统计(分时统计):
    1. 曝光次数、不同用户id数、不同用户数
    2. 点击次数、不同用户id数、不同用户数
    3. 购买次数、不同用户id数、不同用户数
  2. 转化率-漏斗分析
    1. 点击率 = 点击次数 / 曝光次数
    2. 购买率 = 购买次数 / 点击次数
  3. 活动曝光效果评估:
    1. 行为(曝光、点击、购买)、时间段、广告位、产品,统计对应的次数
    2. 时间段、广告位、商品,曝光次数最多的前N个

广告业务ODS层建表及数据加载

  1. ODS创建广告业务明细数据表【ods_log_event】,

    CREATE EXTERNAL TABLE ods.ods_log_event(`str` string)
    PARTITIONED BY (`dt` string)
    STORED AS TEXTFILE
    LOCATION '/user/data/logs/event';
    
  2. 【ods_load_event_log.sh】

    #!/bin/bash
    
    source /etc/profile
    
    if [ -n "$1" ]
    then
    	do_date=$1
    else
    	do_date=`date -d "-1 day" +%F`
    fi
    sql="
    	alter table ods.ods_log_event add partition (dt='$do_date');
    "
    hive -e "$sql"
    
  3. 此时【ods_log_event】表中数据为:

    hive (ods)> select * from ods_log_event limit 1;
    OK
    ods_log_event.str	ods_log_event.dt
    2020-07-21 16:54:41.491 [main] INFO  com.lagou.ecommerce.AppEvent - {"lagou_event":[{"name":"favorites","json":{"course_id":2,"id":0,"userid":0},"time":1595260800000},{"name":"praise","json":{"id":5,"type":1,"add_time":"1631749438222","userid":3,"target":4},"time":1595260800000}],"attr":{"area":"常州","uid":"2F10092A2","app_v":"1.1.18","event_type":"common","device_id":"1FB872-9A1002","os_type":"7.7","channel":"LJ","language":"chinese","brand":"xiaomi-3"}}	2020-07-21
    Time taken: 10.121 seconds, Fetched: 1 row(s)
    

广告业务DWD层建表及数据加载

  1. ODS层的【ods_log_event】表中记录用户事件日志数据信息,事件的主要信息在json串中(json数组),公共信息在另外一个json串中;
  2. DWD层数据来源于ODS层,即ODS => 解析json,从json串中,提取jsonArray数据;将公共信息从json串中解析出来 => 所有事件的明细
  3. 所有事件的明细包含:分区,事件(json串),公共信息字段,然后从所有事件的明细 => 广告json串解析 => 广告事件的明细
  4. 广告事件的明细包含:分区,广告信息字段,公共信息字段

DWD层创建所有事件明细表【dwd_event_log】以及广告点击明细
表【dwd_ad】

-- 所有事件明细
drop table if exists dwd.dwd_event_log;
CREATE EXTERNAL TABLE dwd.dwd_event_log(
	`device_id` string,
	`uid` string,
	`app_v` string,
	`os_type` string,
	`event_type` string,
	`language` string,
	`channel` string,
	`area` string,
	`brand` string,
	`name` string,
	`event_json` string,
	`report_time` string)
PARTITIONED BY (`dt` string)
stored as parquet;

-- 广告点击明细
drop table if exists dwd.dwd_ad;
CREATE TABLE dwd.dwd_ad(
	`device_id` string,
	`uid` string,
	`app_v` string,
	`os_type` string,
	`event_type` string,
	`language` string,
	`channel` string,
	`area` string,
	`brand` string,
	`report_time` string,
	`duration` int,
	`ad_action` int,
	`shop_id` int,
	`ad_type` int,
	`show_style` smallint,
	`product_id` int,
	`place` string,
	`sort` int,
	`hour` string
	)
PARTITIONED BY (`dt` string)
stored as parquet;

DWD层数据加载全部的事件日志【dwd_load_event_log.sh】

#!/bin/bash

source /etc/profile

if [ -n "$1" ] ;then
	do_date=$1
else
	do_date=`date -d "-1 day" +%F`
fi

sql="
use dwd;
add jar /data/lagoudw/jars/cn.lagou.dw-1.0-SNAPSHOT-jar-with-dependencies.jar;
create temporary function json_array as 'cn.lagou.dw.hive.udf.ParseJsonArray';
with tmp_start as
(
	select split(str, ' ')[7] as line
		from ods.ods_log_event
	where dt='$do_date'
)

insert overwrite table dwd.dwd_event_log
PARTITION (dt='$do_date')
select
	device_id,
	uid,
	app_v,
	os_type,
	event_type,
	language,
	channel,
	area,
	brand,
	get_json_object(k,'$.name') as name,
	get_json_object(k,'$.json') as json,
	get_json_object(k,'$.time') as time
from
(
	select
	get_json_object(line,'$.attr.device_id') as device_id,
	get_json_object(line,'$.attr.uid') as uid,
	get_json_object(line,'$.attr.app_v') as app_v,
	get_json_object(line,'$.attr.os_type') as os_type,
	get_json_object(line,'$.attr.event_type') as event_type,
	get_json_object(line,'$.attr.language') as language,
	get_json_object(line,'$.attr.channel') as channel,
	get_json_object(line,'$.attr.area') as area,
	get_json_object(line,'$.attr.brand') as brand,
	get_json_object(line,'$.lagou_event') as lagou_event
from tmp_start
) A lateral view explode(json_array(lagou_event)) B as k
"
hive -e "$sql"

DWD层从全部的事件日志中获取广告事件详细信【dwd_load_ad_log.sh】:

#!/bin/bash

source /etc/profile

if [ -n "$1" ] ;then
	do_date=$1
else
	do_date=`date -d "-1 day" +%F`
fi

sql="
insert overwrite table dwd.dwd_ad
PARTITION (dt='$do_date')
select
	device_id,
	uid,
	app_v,
	os_type,
	event_type,
	language,
	channel,
	area,
	brand,
	report_time,
	get_json_object(event_json,'$.duration') ,
	get_json_object(event_json,'$.ad_action') ,
	get_json_object(event_json,'$.shop_id') ,
	get_json_object(event_json,'$.ad_type'),
	get_json_object(event_json,'$.show_style'),
	get_json_object(event_json,'$.product_id'),
	get_json_object(event_json,'$.place'),
	get_json_object(event_json,'$.sort'),
	from_unixtime(ceil(report_time/1000), 'HH')
from dwd.dwd_event_log
where dt='$do_date' and name='ad';
"
hive -e "$sql"

广告点击次数分析

  1. 广告点击次数需求分析,
  2. 广告的详细数据为:
    1. action。用户行为;0 曝光;1 曝光后点击;2 购买
    2. duration。停留时长
    3. shop_id。商家id
    4. event_type。“ad”
    5. ad_type。格式类型;1 JPG;2 PNG;3 GIF;4 SWF
    6. show_style。显示风格,0 静态图;1 动态图
    7. product_id。产品id
    8. place。广告位置;首页=1,左侧=2,右侧=3,列表页=4
    9. sort。排序位置
  3. 分时统计:
    1. 曝光次数、不同用户id数(公共信息中的uid)、不同用户数(公共信息中的device_id)
    2. 点击次数、不同用户id数、不同用户数(device_id)
    3. 购买次数、不同用户id数、不同用户数(device_id)

创建ADS层表【ads_ad_show】

create table ads.ads_ad_show(
	cnt bigint,
	u_cnt bigint,
	device_cnt bigint,
	ad_action tinyint,
	hour string
) PARTITIONED BY (`dt` string)
row format delimited fields terminated by ',';

加载ADS层数据【ads_load_ad_show.sh】

#!/bin/bash

source /etc/profile
if [ -n "$1" ] ;then
	do_date=$1
else
	do_date=`date -d "-1 day" +%F`
fi

sql="
insert overwrite table ads.ads_ad_show
partition (dt='$do_date')
select count(1),
	count(distinct uid),
	count(distinct device_id),
	ad_action,
	hour
  from dwd.dwd_ad
 where dt='$do_date'
group by ad_action, hour
"
hive -e "$sql"

点击率购买率

点击率购买率需求分析

分时统计:

  1. 点击率 = 点击次数 / 曝光次数
  2. 购买率 = 购买次数 / 点击次数

创建ADS层表点击率购买率表【ads_ad_show_rate】

create table ads.ads_ad_show_rate(
	hour string,
	click_rate double,
	buy_rate double
) PARTITIONED BY (`dt` string)
row format delimited fields terminated by ',';

加载ADS层数据

#!/bin/bash

source /etc/profile

if [ -n "$1" ] ;then
	do_date=$1
else
	do_date=`date -d "-1 day" +%F`
fi

sql="
with tmp as(
		select max(case when ad_action='0' then cnt end) show_cnt,
		max(case when ad_action='1' then cnt end) click_cnt,
		max(case when ad_action='2' then cnt end) buy_cnt,
		hour
	from ads.ads_ad_show
 where dt='$do_date'
group by hour
)
insert overwrite table ads.ads_ad_show_rate
partition (dt='$do_date')
select hour,
		click_cnt / show_cnt as click_rate,
		buy_cnt / click_cnt as buy_rate
	from tmp;
"
hive -e "$sql"

广告效果分析

广告效果需求分析:

  1. 活动曝光效果评估:
    1. 效果表:行为(曝光、点击、购买)、时间段、广告位、商品,统计对应的次数
    2. 排名表:时间段、广告位、商品,曝光次数最多的前100个

创建ADS层广告效果表【ads_ad_show_place】,广告排名表【ads_ad_show_place_window】

create table ads.ads_ad_show_place(
	ad_action tinyint,
	hour string,
	place string,
	product_id int,
	cnt bigint
)PARTITIONED BY (`dt` string)
row format delimited fields terminated by ',';

create table ads.ads_ad_show_place_window(
	hour string,
	place string,
	product_id int,
	cnt bigint,
	rank int
)PARTITIONED BY (`dt` string)
row format delimited fields terminated by ',';

广告效果加载ADS层数据【ads_ad_show_place.sh】

#!/bin/bash

source /etc/profile

if [ -n "$1" ] ;then
	do_date=$1
else
	do_date=`date -d "-1 day" +%F`
fi

sql="
insert overwrite table ads.ads_ad_show_place partition (dt='$do_date')
select ad_action,
		hour,
		place,
		product_id,
		count(1)
	from dwd.dwd_ad
 where dt='$do_date'
group by ad_action, hour, place, product_id;
"
hive -e "$sql"

广告效果加载ADS层数据【ads_ad_show_place_window.sh】

#!/bin/bash

source /etc/profile

if [ -n "$1" ] ;then
	do_date=$1
else
	do_date=`date -d "-1 day" +%F`
fi

sql="
insert overwrite table ads.ads_ad_show_place_window
partition (dt='$do_date')
select *
	from (
		select hour,
		place,
		product_id,
		cnt,
		row_number() over (partition by hour, place,
product_id order by cnt desc) rank
	 from ads.ads_ad_show_place
   where dt='$do_date' and ad_action='0'
  ) t
 where rank <= 100
"
hive -e "$sql"
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一、课程简介随着技术的飞速发展,经过多年的数据积累,各互联网公司已保存了海量的原始数据和各种业务数据,所以数据库技术是各大公司目前都需要着重发展投入的技术领域。数据库是面向分析的集成化数据环境,为企业所有决策制定过程,提供系统数据支持的战略集合。通过对数据库中数据分析,可以帮助企业改进业务流程、控制成本、提高产品质量等。二、课程内容本次精心打造的数项目的课程,从项目架构的搭,到数据采集模块的设计、数架构的设计、实战需求实现、即席查询的实现,我们针对国内目前广泛使用的Apache原生框架和CDH版本框架进行了分别介绍,Apache原生框架介绍中涉及到的技术框架包括Flume、Kafka、Sqoop、MySql、HDFS、Hive、Tez、Spark、Presto、Druid等,CDH版本框架讲解包括CM的安装部署、Hadoop、Zookeeper、Hive、Flume、Kafka、Oozie、Impala、HUE、Kudu、Spark的安装配置,透彻了解不同版本框架的区别联系,将大数据全生态系统前沿技术一网打尽。在过程中对大数据生态体系进行了系统的讲解,对实际企业数项目中可能涉及到的技术点都进行了深入的讲解和探讨。同时穿插了大量数基础理论知识,让你在掌握实战经验的同时能够打下坚实的理论基础。三、课程目标本课程以国内电商巨头实际业务应用场景为依托,对电商数的常见实战指标以及难点实战指标进行了详尽讲解,具体指标包括:每日、周、月活跃设备明细,留存用户比例,沉默用户、回流用户、流失用户统计,最近连续3周活跃用户统计,最近7天内连续3天活跃用户统计,GMV成交总额分析,转化及漏斗分析,品牌复购分析、订单拉链的设计等,让学生拥有更直观全面的实战经验。通过对本课程的学习,对数项目可以立起清晰明确的概念,系统全面的掌握各项数项目技术,轻松应对各种数难题。四、课程亮点本课程结合国内多家企业实际项目经验,特别入了项目架构模块,从集群规模的确定到框架版本选型以及服务器选型,手把手教你从零开始搭数据集群。并且总结大量项目实战中会遇到的问题,针对各个技术框架,均有调优实战经验,具体包括:常用Linux运维命令、Hadoop集群调优、Flume组件选型及性能优化、Kafka集群规模确认及关键参数调优。通过这部分学习,助学生迅速成长,获取前沿技术经验,从容解决实战问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值