Commit 86c943f2 authored by litaolemo's avatar litaolemo

update

parent ba9a569c
...@@ -83,30 +83,29 @@ for t in range(0, 3): ...@@ -83,30 +83,29 @@ for t in range(0, 3):
ctr_sql = """ ctr_sql = """
SELECT SELECT
t1.partition_date as day_id, t1.partition_date as day_id,
t1.device_os_type as device_os_type, t1.device_os_type as device_os_type,
t1.active_type as active_type, t1.active_type as active_type,
t2.card_content_type as card_content_type, t2.card_content_type as card_content_type,
t2.recommend_type as recommend_type, t2.recommend_type as recommend_type,
NVL(sum(t3.session_pv),0) as card_click, NVL(sum(t3.session_pv),0) as card_click,
NVL(sum(t2.session_pv),0) as card_exposure, NVL(sum(t2.session_pv),0) as card_exposure,
NVL(round(sum(page_stay)/count(distinct t4.cl_id)/60,2),0) as avg_page_stay, NVL(round(sum(page_stay)/count(distinct t4.cl_id)/60,2),0) as avg_page_stay,
NVL(sum(t4_pv.pv),0) as page_pv, NVL(sum(t4_pv.pv),0) as page_pv,
NVL(sum(t4_pv.pv_20),0) as page_pv_20, NVL(sum(t4_pv.pv_20),0) as page_pv_20,
NVL(sum(navbar_pv),0) as navbar_search, NVL(sum(navbar_pv),0) as navbar_search,
NVL(sum(highlight_pv),0) as highlight_word, NVL(sum(highlight_pv),0) as highlight_word,
NVL(sum(self_wel_pv),0) as self_welfare_card, NVL(sum(self_wel_pv),0) as self_welfare_card,
NVL(sum(recom_wel_pv),0)-NVL(sum(self_wel_pv),0) as recommend_welfare_card,--需要排除关联的商品卡片点击 NVL(sum(recom_wel_pv),0)-NVL(sum(self_wel_pv),0) as recommend_welfare_card,--需要排除关联的商品卡片点击
NVL(sum(recom_content_pv),0) as recommend_content_card, NVL(sum(recom_content_pv),0) as recommend_content_card,
NULL as recommend_special_card, NULL as recommend_special_card,
NVL(sum(referral_pv),0) as transfer_card, NVL(sum(referral_pv),0) as transfer_card,
NVL(sum(video_pv),0) as video_consultation, NVL(sum(video_pv),0) as video_consultation,
NVL(sum(post_pv),0) as total_post_pv, NVL(sum(post_pv),0) as total_post_pv,
NVL(sum(post_click_pv),0) as post_click_pv NVL(sum(post_click_pv),0) as post_click_pv
FROM
FROM
( (
SELECT partition_date SELECT partition_date
,device_os_type ,device_os_type
...@@ -114,7 +113,7 @@ for t in range(0, 3): ...@@ -114,7 +113,7 @@ for t in range(0, 3):
WHEN active_type IN ('1','2') THEN '新增' END AS active_type WHEN active_type IN ('1','2') THEN '新增' END AS active_type
,device_id ,device_id
FROM online.ml_device_day_active_status FROM online.ml_device_day_active_status
WHERE partition_date={partition_day} WHERE partition_date='{partition_day}'
AND active_type IN ('1','2','4') AND active_type IN ('1','2','4')
AND first_channel_source_type not IN ('yqxiu1','yqxiu2','yqxiu3','yqxiu4','yqxiu5','mxyc1','mxyc2','mxyc3' AND first_channel_source_type not IN ('yqxiu1','yqxiu2','yqxiu3','yqxiu4','yqxiu5','mxyc1','mxyc2','mxyc3'
,'wanpu','jinshan','jx','maimai','zhuoyi','huatian','suopingjingling','mocha','mizhe','meika','lamabang' ,'wanpu','jinshan','jx','maimai','zhuoyi','huatian','suopingjingling','mocha','mizhe','meika','lamabang'
...@@ -124,568 +123,543 @@ for t in range(0, 3): ...@@ -124,568 +123,543 @@ for t in range(0, 3):
,'promotion_qianka','promotion_xiaoyu','promotion_dianru','promotion_malioaso','promotion_malioaso-shequ' ,'promotion_qianka','promotion_xiaoyu','promotion_dianru','promotion_malioaso','promotion_malioaso-shequ'
,'promotion_shike','promotion_julang_jl03','promotion_zuimei') ,'promotion_shike','promotion_julang_jl03','promotion_zuimei')
AND first_channel_source_type not LIKE 'promotion\_jf\_%' AND first_channel_source_type not LIKE 'promotion\_jf\_%'
)t1 JOIN )t1
JOIN
(--卡片,卡片id和session_id去重 (--精准曝光,卡片id和session_id去重
SELECT partition_date, SELECT partition_date,
cl_id, card_content_type,
count(distinct card_id) as session_pv0 cl_id,
FROM v.recommend_type,
(SELECT partition_date, card_id,
cl_id, count(distinct app_session_id) as session_pv
card_id, FROM
app_session_id (
from online.ml_community_precise_exposure_detail SELECT partition_date,
WHERE partition_date={partition_day} cl_id,
AND action in ('page_precise_exposure','home_choiceness_card_exposure') --7745版本action改为page_precise_exposure case when card_content_type in ('qa','answer') then 'qa'
AND is_exposure = '1' ----精准曝光 when card_content_type in ('special_pool') then 'special' else card_content_type end as card_content_type,
AND page_name ='home' CASE when transaction_type in ('fmctr','samecity_fmctr') then array('fmctr','合计')
AND tab_name = '精选' when transaction_type in ('high_quality_fmctr') then array('high_quality_fmctr','合计')
AND (transaction_type in ('-1','smr','hotspot','pgc','newdata','hotspot_feed','aistragegy','excestragegy','FIXEDSTRATEGY','FIXEDSTRATEGY_VIDEO') WHEN (transaction_type like '%ctr' and transaction_type not in ('high_quality_ctr','high_quality_fmctr','fmctr','samecity_fmctr') ) THEN array('ctr预估','合计')
or transaction_type like '%ctr' or transaction_type like '%cvr' or transaction_type like 'deeplink%') when transaction_type in ('high_quality_ctr') then array('high_quality_ctr','合计')
AND card_content_type in ('qa','diary','user_post','answer','special_pool') WHEN transaction_type like '%cvr' THEN array('cvr预估','合计')
group by partition_date, WHEN transaction_type in ('-1','smr') THEN array('smr','合计')
cl_id, when transaction_type in ('pgc','hotspot') then array('热点卡片')
card_id, when transaction_type in ('newdata') then array('保量卡片')
app_session_id when transaction_type in ('hotspot_feed') then array('hotspot_feed','合计')
)a when transaction_type in ('aistragegy') then array('新用户AI帖优先','合计')
group by partition_date,cl_id when transaction_type in ('excestragegy') then array('新用户精华帖优先','合计')
) t0 on t1.device_id = t0.cl_id when transaction_type in ('FIXEDSTRATEGY') then array('新氧新用户策略一','合计')
LEFT JOIN when transaction_type in ('FIXEDSTRATEGY_VIDEO') then array('新氧新用户策略二','合计')
(--精准曝光,卡片id和session_id去重 when transaction_type like 'deeplink%' then array('deeplink策略','合计')
SELECT partition_date, end AS recommend_type,
card_content_type, card_id,
cl_id, app_session_id
v.recommend_type, from online.ml_community_precise_exposure_detail
card_id, WHERE partition_date='{partition_day}'
count(distinct app_session_id) as session_pv AND action in ('page_precise_exposure','home_choiceness_card_exposure') --7745版本action改为page_precise_exposure
FROM AND is_exposure = '1' ----精准曝光
( AND page_name ='home'
SELECT partition_date, AND tab_name = '精选'
cl_id, AND (transaction_type in ('-1','smr','hotspot','pgc','newdata','hotspot_feed','aistragegy','excestragegy','FIXEDSTRATEGY','FIXEDSTRATEGY_VIDEO')
case when card_content_type in ('qa','answer') then 'qa' or transaction_type like '%ctr' or transaction_type like '%cvr' or transaction_type like 'deeplink%')
when card_content_type in ('special_pool') then 'special' else card_content_type end as card_content_type, AND card_content_type in ('qa','diary','user_post','answer','special_pool')
CASE when transaction_type in ('fmctr','samecity_fmctr') then array('fmctr','合计') group by partition_date,
when transaction_type in ('high_quality_fmctr') then array('high_quality_fmctr','合计') case when card_content_type in ('qa','answer') then 'qa'
WHEN (transaction_type like '%ctr' and transaction_type not in ('high_quality_ctr','high_quality_fmctr','fmctr','samecity_fmctr') ) THEN array('ctr预估','合计') when card_content_type in ('special_pool') then 'special' else card_content_type end,
when transaction_type in ('high_quality_ctr') then array('high_quality_ctr','合计') cl_id,
WHEN transaction_type like '%cvr' THEN array('cvr预估','合计') CASE when transaction_type in ('fmctr','samecity_fmctr') then array('fmctr','合计')
WHEN transaction_type in ('-1','smr') THEN array('smr','合计') when transaction_type in ('high_quality_fmctr') then array('high_quality_fmctr','合计')
when transaction_type in ('pgc','hotspot') then array('热点卡片') WHEN (transaction_type like '%ctr' and transaction_type not in ('high_quality_ctr','high_quality_fmctr','fmctr','samecity_fmctr')) THEN array('ctr预估','合计')
when transaction_type in ('newdata') then array('保量卡片') when transaction_type in ('high_quality_ctr') then array('high_quality_ctr','合计')
when transaction_type in ('hotspot_feed') then array('hotspot_feed','合计') WHEN transaction_type like '%cvr' THEN array('cvr预估','合计')
when transaction_type in ('aistragegy') then array('新用户AI帖优先','合计') WHEN transaction_type in ('-1','smr') THEN array('smr','合计')
when transaction_type in ('excestragegy') then array('新用户精华帖优先','合计') when transaction_type in ('pgc','hotspot') then array('热点卡片')
when transaction_type in ('FIXEDSTRATEGY') then array('新氧新用户策略一','合计') when transaction_type in ('newdata') then array('保量卡片')
when transaction_type in ('FIXEDSTRATEGY_VIDEO') then array('新氧新用户策略二','合计') when transaction_type in ('hotspot_feed') then array('hotspot_feed','合计')
when transaction_type like 'deeplink%' then array('deeplink策略','合计') when transaction_type in ('aistragegy') then array('新用户AI帖优先','合计')
end AS recommend_type, when transaction_type in ('excestragegy') then array('新用户精华帖优先','合计')
card_id, when transaction_type in ('FIXEDSTRATEGY') then array('新氧新用户策略一','合计')
app_session_id when transaction_type in ('FIXEDSTRATEGY_VIDEO') then array('新氧新用户策略二','合计')
from online.ml_community_precise_exposure_detail when transaction_type like 'deeplink%' then array('deeplink策略','合计') end,
WHERE partition_date={partition_day} card_id,
AND action in ('page_precise_exposure','home_choiceness_card_exposure') --7745版本action改为page_precise_exposure app_session_id
AND is_exposure = '1' ----精准曝光 )a
AND page_name ='home' LATERAL VIEW explode (a.recommend_type) v as recommend_type
AND tab_name = '精选' group by partition_date,card_content_type,cl_id,v.recommend_type,card_id
AND (transaction_type in ('-1','smr','hotspot','pgc','newdata','hotspot_feed','aistragegy','excestragegy','FIXEDSTRATEGY','FIXEDSTRATEGY_VIDEO') )t2
or transaction_type like '%ctr' or transaction_type like '%cvr' or transaction_type like 'deeplink%') on t1.device_id=t2.cl_id and t1.partition_date=t2.partition_date
AND card_content_type in ('qa','diary','user_post','answer','special_pool') LEFT JOIN
group by partition_date, (--卡片,卡片id和session_id去重
case when card_content_type in ('qa','answer') then 'qa' SELECT partition_date,
when card_content_type in ('special_pool') then 'special' else card_content_type end, card_content_type,
cl_id, cl_id,
CASE when transaction_type in ('fmctr','samecity_fmctr') then array('fmctr','合计') v.recommend_type,
when transaction_type in ('high_quality_fmctr') then array('high_quality_fmctr','合计') card_id,
WHEN (transaction_type like '%ctr' and transaction_type not in ('high_quality_ctr','high_quality_fmctr','fmctr','samecity_fmctr')) THEN array('ctr预估','合计') count(distinct app_session_id) as session_pv
when transaction_type in ('high_quality_ctr') then array('high_quality_ctr','合计') FROM
WHEN transaction_type like '%cvr' THEN array('cvr预估','合计') (
WHEN transaction_type in ('-1','smr') THEN array('smr','合计') SELECT partition_date,
when transaction_type in ('pgc','hotspot') then array('热点卡片') cl_id,
when transaction_type in ('newdata') then array('保量卡片') case when params['card_content_type'] in ('qa','answer') then 'qa'
when transaction_type in ('hotspot_feed') then array('hotspot_feed','合计') when params['card_content_type'] in ('special_pool') then 'special' else params['card_content_type'] end as card_content_type,
when transaction_type in ('aistragegy') then array('新用户AI帖优先','合计') CASE when params['transaction_type'] in ('fmctr','samecity_fmctr') then array('fmctr','合计')
when transaction_type in ('excestragegy') then array('新用户精华帖优先','合计') when params['transaction_type'] in ('high_quality_fmctr') then array('high_quality_fmctr','合计')
when transaction_type in ('FIXEDSTRATEGY') then array('新氧新用户策略一','合计') WHEN (params['transaction_type'] like '%ctr' and params['transaction_type'] not in ('high_quality_ctr','high_quality_fmctr','fmctr','samecity_fmctr')) THEN array('ctr预估','合计')
when transaction_type in ('FIXEDSTRATEGY_VIDEO') then array('新氧新用户策略二','合计') when params['transaction_type'] in ('high_quality_ctr') then array('high_quality_ctr','合计')
when transaction_type like 'deeplink%' then array('deeplink策略','合计') end, WHEN params['transaction_type'] like '%cvr' THEN array('cvr预估','合计')
card_id, WHEN params['transaction_type'] in ('-1','smr') THEN array('smr','合计')
app_session_id when params['transaction_type'] in ('pgc','hotspot') then array('热点卡片')
)a when params['transaction_type'] in ('newdata') then array('保量卡片')
LATERAL VIEW explode (a.recommend_type) v as recommend_type when params['transaction_type'] in ('hotspot_feed') then array('hotspot_feed','合计')
group by partition_date,card_content_type,cl_id,v.recommend_type,card_id when params['transaction_type'] in ('aistragegy') then array('新用户AI帖优先','合计')
)t2 when params['transaction_type'] in ('excestragegy') then array('新用户精华帖优先','合计')
on t0.cl_id=t2.cl_id and t0.partition_date=t2.partition_date when params['transaction_type'] in ('FIXEDSTRATEGY') then array('新氧新用户策略一','合计')
LEFT JOIN when params['transaction_type'] in ('FIXEDSTRATEGY_VIDEO') then array('新氧新用户策略二','合计')
(--卡片,卡片id和session_id去重 when params['transaction_type'] like 'deeplink%' then array('deeplink策略','合计')
SELECT partition_date, end AS recommend_type,
card_content_type, params['card_id'] as card_id,
cl_id, app_session_id
v.recommend_type, from online.bl_hdfs_maidian_updates
card_id, WHERE partition_date='{partition_day}'
count(distinct app_session_id) as session_pv AND action='on_click_card'
FROM AND params['page_name'] ='home'
( AND params['tab_name'] = '精选'
SELECT partition_date, AND (params['transaction_type'] in ('-1','smr','hotspot','pgc','newdata','hotspot_feed','aistragegy','excestragegy','FIXEDSTRATEGY','FIXEDSTRATEGY_VIDEO')
cl_id, or params['transaction_type'] like '%ctr' or params['transaction_type'] like '%cvr' or params['transaction_type'] like 'deeplink%')
case when params['card_content_type'] in ('qa','answer') then 'qa' AND params['card_content_type'] in ('qa','diary','user_post','answer','special_pool')
when params['card_content_type'] in ('special_pool') then 'special' else params['card_content_type'] end as card_content_type, GROUP BY partition_date,
CASE when params['transaction_type'] in ('fmctr','samecity_fmctr') then array('fmctr','合计') cl_id,
when params['transaction_type'] in ('high_quality_fmctr') then array('high_quality_fmctr','合计') case when params['card_content_type'] in ('qa','answer') then 'qa'
WHEN (params['transaction_type'] like '%ctr' and params['transaction_type'] not in ('high_quality_ctr','high_quality_fmctr','fmctr','samecity_fmctr')) THEN array('ctr预估','合计') when params['card_content_type'] in ('special_pool') then 'special' else params['card_content_type'] end,
when params['transaction_type'] in ('high_quality_ctr') then array('high_quality_ctr','合计') CASE when params['transaction_type'] in ('fmctr','samecity_fmctr') then array('fmctr','合计')
WHEN params['transaction_type'] like '%cvr' THEN array('cvr预估','合计') when params['transaction_type'] in ('high_quality_fmctr') then array('high_quality_fmctr','合计')
WHEN params['transaction_type'] in ('-1','smr') THEN array('smr','合计') WHEN (params['transaction_type'] like '%ctr' and params['transaction_type'] not in ('high_quality_ctr','high_quality_fmctr','fmctr','samecity_fmctr')) THEN array('ctr预估','合计')
when params['transaction_type'] in ('pgc','hotspot') then array('热点卡片') when params['transaction_type'] in ('high_quality_ctr') then array('high_quality_ctr','合计')
when params['transaction_type'] in ('newdata') then array('保量卡片') WHEN params['transaction_type'] like '%cvr' THEN array('cvr预估','合计')
when params['transaction_type'] in ('hotspot_feed') then array('hotspot_feed','合计') WHEN params['transaction_type'] in ('-1','smr') THEN array('smr','合计')
when params['transaction_type'] in ('aistragegy') then array('新用户AI帖优先','合计') when params['transaction_type'] in ('pgc','hotspot') then array('热点卡片')
when params['transaction_type'] in ('excestragegy') then array('新用户精华帖优先','合计') when params['transaction_type'] in ('newdata') then array('保量卡片')
when params['transaction_type'] in ('FIXEDSTRATEGY') then array('新氧新用户策略一','合计') when params['transaction_type'] in ('hotspot_feed') then array('hotspot_feed','合计')
when params['transaction_type'] in ('FIXEDSTRATEGY_VIDEO') then array('新氧新用户策略二','合计') when params['transaction_type'] in ('aistragegy') then array('新用户AI帖优先','合计')
when params['transaction_type'] like 'deeplink%' then array('deeplink策略','合计') when params['transaction_type'] in ('excestragegy') then array('新用户精华帖优先','合计')
end AS recommend_type, when params['transaction_type'] in ('FIXEDSTRATEGY') then array('新氧新用户策略一','合计')
params['card_id'] as card_id, when params['transaction_type'] in ('FIXEDSTRATEGY_VIDEO') then array('新氧新用户策略二','合计')
app_session_id when params['transaction_type'] like 'deeplink%' then array('deeplink策略','合计') end,
from online.bl_hdfs_maidian_updates params['card_id'],
WHERE partition_date={partition_day} app_session_id
AND action='on_click_card' )a
AND params['page_name'] ='home' LATERAL VIEW explode (a.recommend_type) v as recommend_type
AND params['tab_name'] = '精选' group by partition_date,card_content_type,cl_id,v.recommend_type,card_id
AND (params['transaction_type'] in ('-1','smr','hotspot','pgc','newdata','hotspot_feed','aistragegy','excestragegy','FIXEDSTRATEGY','FIXEDSTRATEGY_VIDEO') )t3
or params['transaction_type'] like '%ctr' or params['transaction_type'] like '%cvr' or params['transaction_type'] like 'deeplink%') on t2.partition_date=t3.partition_date
AND params['card_content_type'] in ('qa','diary','user_post','answer','special_pool') and t2.cl_id=t3.cl_id
GROUP BY partition_date, and t2.card_id=t3.card_id
cl_id, and t2.card_content_type=t3.card_content_type
case when params['card_content_type'] in ('qa','answer') then 'qa' and t2.recommend_type=t3.recommend_type
when params['card_content_type'] in ('special_pool') then 'special' else params['card_content_type'] end, LEFT JOIN
CASE when params['transaction_type'] in ('fmctr','samecity_fmctr') then array('fmctr','合计') (--页面浏览时长
when params['transaction_type'] in ('high_quality_fmctr') then array('high_quality_fmctr','合计') select partition_date,cl_id,coalesce(b.id,a.business_id) as business_id,a.page_name
WHEN (params['transaction_type'] like '%ctr' and params['transaction_type'] not in ('high_quality_ctr','high_quality_fmctr','fmctr','samecity_fmctr')) THEN array('ctr预估','合计') ,sum(page_stay) as page_stay
when params['transaction_type'] in ('high_quality_ctr') then array('high_quality_ctr','合计') from
WHEN params['transaction_type'] like '%cvr' THEN array('cvr预估','合计') (
WHEN params['transaction_type'] in ('-1','smr') THEN array('smr','合计') SELECT partition_date,cl_id,business_id,
when params['transaction_type'] in ('pgc','hotspot') then array('热点卡片') case when page_name in ('diary_detail','topic_detail') then 'diary'
when params['transaction_type'] in ('newdata') then array('保量卡片') when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
when params['transaction_type'] in ('hotspot_feed') then array('hotspot_feed','合计') when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
when params['transaction_type'] in ('aistragegy') then array('新用户AI帖优先','合计') when page_name in ('custom_special') then 'special' else null end as page_name,
when params['transaction_type'] in ('excestragegy') then array('新用户精华帖优先','合计') page_stay,time_str
when params['transaction_type'] in ('FIXEDSTRATEGY') then array('新氧新用户策略一','合计') FROM online.bl_hdfs_maidian_updates
when params['transaction_type'] in ('FIXEDSTRATEGY_VIDEO') then array('新氧新用户策略二','合计') WHERE partition_date='{partition_day}'
when params['transaction_type'] like 'deeplink%' then array('deeplink策略','合计') end, AND action='page_view'
params['card_id'], AND page_name IN ('diary_detail','topic_detail','post_detail','user_post_detail','doctor_post_detail','question_detail','answer_detail','question_answer_detail','custom_special')
app_session_id AND referrer='home'
)a AND page_stay>=0 AND page_stay<1000
LATERAL VIEW explode (a.recommend_type) v as recommend_type GROUP BY partition_date,cl_id,business_id,
group by partition_date,card_content_type,cl_id,v.recommend_type,card_id case when page_name in ('diary_detail','topic_detail') then 'diary'
)t3 when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
on t2.partition_date=t3.partition_date when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
and t2.cl_id=t3.cl_id when page_name in ('custom_special') then 'special' else null end,page_stay,time_str
and t2.card_id=t3.card_id )a
and t2.card_content_type=t3.card_content_type left join
and t2.recommend_type=t3.recommend_type (
LEFT JOIN select id,visual_page_id,'special' as page_name
(--页面浏览时长 from tl.tl_zx_api_special_pool
select partition_date,cl_id,coalesce(b.id,a.business_id) as business_id,a.page_name where partition_day ='{partition_day}'
,sum(page_stay) as page_stay group by id,visual_page_id
from )b
( on a.business_id=b.visual_page_id and a.page_name=b.page_name
SELECT partition_date,cl_id,business_id, group by partition_date,cl_id,coalesce(b.id,a.business_id),a.page_name
case when page_name in ('diary_detail','topic_detail') then 'diary' )t4
when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post' on t4.partition_date=t3.partition_date
when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa' and t4.cl_id=t3.cl_id
when page_name in ('custom_special') then 'special' else null end as page_name, and t4.business_id=t3.card_id
page_stay,time_str and t4.page_name=t3.card_content_type
FROM online.bl_hdfs_maidian_updates LEFT JOIN
WHERE partition_date={partition_day} (--页面浏览时长
AND action='page_view' select partition_date,cl_id,coalesce(b.id,a.business_id) as business_id,a.page_name
AND page_name IN ('diary_detail','topic_detail','post_detail','user_post_detail','doctor_post_detail','question_detail','answer_detail','question_answer_detail','custom_special') ,count(1) as pv
AND referrer='home' ,count(case when page_stay>=20 then 1 end) as pv_20
AND page_stay>=0 AND page_stay<1000 from
GROUP BY partition_date,cl_id,business_id, (
case when page_name in ('diary_detail','topic_detail') then 'diary' SELECT partition_date,cl_id,business_id,
when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post' case when page_name in ('diary_detail','topic_detail') then 'diary'
when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa' when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
when page_name in ('custom_special') then 'special' else null end,page_stay,time_str when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
)a when page_name in ('custom_special') then 'special' else null end as page_name,time_str,page_stay
left join FROM online.bl_hdfs_maidian_updates
( WHERE partition_date='{partition_day}'
select id,visual_page_id,'special' as page_name AND action='page_view'
from tl.tl_zx_api_special_pool AND page_name IN ('diary_detail','topic_detail','post_detail','user_post_detail','doctor_post_detail','question_detail','answer_detail','question_answer_detail','custom_special')
where partition_day ={partition_day} AND referrer='home'
group by id,visual_page_id GROUP BY partition_date,cl_id,business_id,
)b case when page_name in ('diary_detail','topic_detail') then 'diary'
on a.business_id=b.visual_page_id and a.page_name=b.page_name when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
group by partition_date,cl_id,coalesce(b.id,a.business_id),a.page_name when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
)t4 when page_name in ('custom_special') then 'special' else null end,time_str,page_stay
on t4.partition_date=t3.partition_date )a
and t4.cl_id=t3.cl_id left join
and t4.business_id=t3.card_id (--在8月份新增了内容专题卡片,需要转换下id
and t4.page_name=t3.card_content_type select id,visual_page_id,'special' as page_name
LEFT JOIN from tl.tl_zx_api_special_pool
(--页面浏览时长 where partition_day ='{partition_day}'
select partition_date,cl_id,coalesce(b.id,a.business_id) as business_id,a.page_name group by id,visual_page_id
,count(1) as pv )b
,count(case when page_stay>=20 then 1 end) as pv_20 on a.business_id=b.visual_page_id and a.page_name=b.page_name
from group by partition_date,cl_id,coalesce(b.id,a.business_id),a.page_name
( )t4_pv
SELECT partition_date,cl_id,business_id, on t4_pv.partition_date=t3.partition_date
case when page_name in ('diary_detail','topic_detail') then 'diary' and t4_pv.cl_id=t3.cl_id
when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post' and t4_pv.business_id=t3.card_id
when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa' and t4_pv.page_name=t3.card_content_type
when page_name in ('custom_special') then 'special' else null end as page_name,time_str,page_stay LEFT JOIN
FROM online.bl_hdfs_maidian_updates (--搜索框和点击行为
WHERE partition_date={partition_day} select partition_date,cl_id,coalesce(b.id,a.business_id) as business_id,a.page_name,navbar_pv
AND action='page_view' from
AND page_name IN ('diary_detail','topic_detail','post_detail','user_post_detail','doctor_post_detail','question_detail','answer_detail','question_answer_detail','custom_special') (
AND referrer='home' SELECT partition_date,cl_id,business_id,
GROUP BY partition_date,cl_id,business_id, case when page_name in ('diary_detail','topic_detail') then 'diary'
case when page_name in ('diary_detail','topic_detail') then 'diary' when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post' when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa' when page_name in ('custom_special') then 'special' else null end as page_name,
when page_name in ('custom_special') then 'special' else null end,time_str,page_stay count(1) as navbar_pv
)a FROM online.bl_hdfs_maidian_updates
left join WHERE partition_date='{partition_day}'
(--在8月份新增了内容专题卡片,需要转换下id AND action in ('on_click_navbar_search','do_search')
select id,visual_page_id,'special' as page_name AND page_name IN ('diary_detail','topic_detail','post_detail','user_post_detail','doctor_post_detail','question_detail','answer_detail','question_answer_detail','custom_special')
from tl.tl_zx_api_special_pool AND (referrer='home' or
where partition_day ={partition_day} (params['referrer_link'] like '%[%' and
group by id,visual_page_id json_split(params['referrer_link'])[size(json_split(params['referrer_link']))-1]='home'))
)b group by partition_date,cl_id,business_id,
on a.business_id=b.visual_page_id and a.page_name=b.page_name case when page_name in ('diary_detail','topic_detail') then 'diary'
group by partition_date,cl_id,coalesce(b.id,a.business_id),a.page_name when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
)t4_pv when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
on t4_pv.partition_date=t3.partition_date when page_name in ('custom_special') then 'special' else null end
and t4_pv.cl_id=t3.cl_id )a
and t4_pv.business_id=t3.card_id left join
and t4_pv.page_name=t3.card_content_type (
LEFT JOIN select id,visual_page_id,'special' as page_name
(--搜索框和点击行为 from tl.tl_zx_api_special_pool
select partition_date,cl_id,coalesce(b.id,a.business_id) as business_id,a.page_name,navbar_pv where partition_day ='{partition_day}'
from group by id,visual_page_id
( )b
SELECT partition_date,cl_id,business_id, on a.business_id=b.visual_page_id and a.page_name=b.page_name
case when page_name in ('diary_detail','topic_detail') then 'diary' )t5
when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post' on t5.partition_date=t3.partition_date
when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa' and t5.cl_id=t3.cl_id
when page_name in ('custom_special') then 'special' else null end as page_name, and t5.business_id=t3.card_id
count(1) as navbar_pv and t5.page_name=t3.card_content_type
FROM online.bl_hdfs_maidian_updates LEFT JOIN
WHERE partition_date={partition_day} (--点击高亮词
AND action in ('on_click_navbar_search','do_search') select partition_date,cl_id,coalesce(b.id,a.business_id) as business_id,a.page_name,highlight_pv
AND page_name IN ('diary_detail','topic_detail','post_detail','user_post_detail','doctor_post_detail','question_detail','answer_detail','question_answer_detail','custom_special') from
AND (referrer='home' or (
(params['referrer_link'] like '%[%' and SELECT partition_date,cl_id,business_id,
json_split(params['referrer_link'])[size(json_split(params['referrer_link']))-1]='home')) case when page_name in ('diary_detail','topic_detail') then 'diary'
group by partition_date,cl_id,business_id, when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
case when page_name in ('diary_detail','topic_detail') then 'diary' when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post' when page_name in ('custom_special') then 'special' else null end as page_name,
when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa' count(1) as highlight_pv
when page_name in ('custom_special') then 'special' else null end FROM online.bl_hdfs_maidian_updates
)a WHERE partition_date='{partition_day}'
left join AND action='on_click_card'
( and params['card_type']='highlight_word'
select id,visual_page_id,'special' as page_name AND page_name IN ('diary_detail','topic_detail','post_detail','user_post_detail','doctor_post_detail','question_detail','answer_detail','question_answer_detail','custom_special')
from tl.tl_zx_api_special_pool AND (referrer='home' or
where partition_day ={partition_day} (params['referrer_link'] like '%[%' and
group by id,visual_page_id json_split(params['referrer_link'])[size(json_split(params['referrer_link']))-1]='home'))
)b group by partition_date,cl_id,business_id,
on a.business_id=b.visual_page_id and a.page_name=b.page_name case when page_name in ('diary_detail','topic_detail') then 'diary'
)t5 when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
on t5.partition_date=t3.partition_date when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
and t5.cl_id=t3.cl_id when page_name in ('custom_special') then 'special' else null end
and t5.business_id=t3.card_id )a
and t5.page_name=t3.card_content_type left join
LEFT JOIN (
(--点击高亮词 select id,visual_page_id,'special' as page_name
select partition_date,cl_id,coalesce(b.id,a.business_id) as business_id,a.page_name,highlight_pv from tl.tl_zx_api_special_pool
from where partition_day ='{partition_day}'
( group by id,visual_page_id
SELECT partition_date,cl_id,business_id, )b
case when page_name in ('diary_detail','topic_detail') then 'diary' on a.business_id=b.visual_page_id and a.page_name=b.page_name
when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post' )t6
when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa' on t6.partition_date=t3.partition_date
when page_name in ('custom_special') then 'special' else null end as page_name, and t6.cl_id=t3.cl_id
count(1) as highlight_pv and t6.business_id=t3.card_id
FROM online.bl_hdfs_maidian_updates and t6.page_name=t3.card_content_type
WHERE partition_date={partition_day} LEFT JOIN
AND action='on_click_card' (--关联的美购卡片
and params['card_type']='highlight_word' SELECT partition_date,cl_id,coalesce(b.id,a.business_id) as business_id,a.page_name,count(1) as self_wel_pv
AND page_name IN ('diary_detail','topic_detail','post_detail','user_post_detail','doctor_post_detail','question_detail','answer_detail','question_answer_detail','custom_special') FROM
AND (referrer='home' or (
(params['referrer_link'] like '%[%' and SELECT partition_date,cl_id,business_id,app_session_id,params['card_id'] as card_id,
json_split(params['referrer_link'])[size(json_split(params['referrer_link']))-1]='home')) case when page_name in ('diary_detail','topic_detail') then 'diary'
group by partition_date,cl_id,business_id, when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
case when page_name in ('diary_detail','topic_detail') then 'diary' when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post' when page_name in ('custom_special') then 'special' else null end as page_name,
when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa' count(1) as pv
when page_name in ('custom_special') then 'special' else null end FROM online.bl_hdfs_maidian_updates
)a WHERE partition_date='{partition_day}'
left join AND (get_json_object(params['extra_param'], '$.type')='交互栏'
( or get_json_object(params['extra_param'], '$.jump_from')='msg_link'
select id,visual_page_id,'special' as page_name or params['in_page_pos']='top'
from tl.tl_zx_api_special_pool or (params['in_page_pos']='bottom' and params['position'] is null and cl_type='android')
where partition_day ={partition_day} or (params['in_page_pos']='bottom' and params['card_but_pos'] is not null and cl_type='ios'))
group by id,visual_page_id AND action='on_click_card'
)b and params['card_content_type']='service'
on a.business_id=b.visual_page_id and a.page_name=b.page_name AND page_name IN ('diary_detail','topic_detail')
)t6 AND (referrer='home' or
on t6.partition_date=t3.partition_date (params['referrer_link'] like '%[%' and
and t6.cl_id=t3.cl_id json_split(params['referrer_link'])[size(json_split(params['referrer_link']))-1]='home'))
and t6.business_id=t3.card_id group by partition_date,cl_id,business_id,app_session_id,params['card_id'],
and t6.page_name=t3.card_content_type case when page_name in ('diary_detail','topic_detail') then 'diary'
LEFT JOIN when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
(--关联的美购卡片 when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
SELECT partition_date,cl_id,coalesce(b.id,a.business_id) as business_id,a.page_name,count(1) as self_wel_pv when page_name in ('custom_special') then 'special' else null end
FROM )a
( left join
SELECT partition_date,cl_id,business_id,app_session_id,params['card_id'] as card_id, (
case when page_name in ('diary_detail','topic_detail') then 'diary' select id,visual_page_id,'special' as page_name
when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post' from tl.tl_zx_api_special_pool
when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa' where partition_day ='{partition_day}'
when page_name in ('custom_special') then 'special' else null end as page_name, group by id,visual_page_id
count(1) as pv )b
FROM online.bl_hdfs_maidian_updates on a.business_id=b.visual_page_id and a.page_name=b.page_name
WHERE partition_date={partition_day} group by partition_date,cl_id,coalesce(b.id,a.business_id),a.page_name
AND (get_json_object(params['extra_param'], '$.type')='交互栏' )t7
or get_json_object(params['extra_param'], '$.jump_from')='msg_link' on t7.partition_date=t3.partition_date
or params['in_page_pos']='top' and t7.cl_id=t3.cl_id
or (params['in_page_pos']='bottom' and params['position'] is null and cl_type='android') and t7.business_id=t3.card_id
or (params['in_page_pos']='bottom' and params['card_but_pos'] is not null and cl_type='ios')) and t7.page_name=t3.card_content_type
AND action='on_click_card' LEFT JOIN
and params['card_content_type']='service' (--推荐的美购卡片(需要排除作者消费的美购)
AND page_name IN ('diary_detail','topic_detail') SELECT partition_date,cl_id,coalesce(b.id,a.business_id) as business_id,a.page_name,count(1) as recom_wel_pv
AND (referrer='home' or FROM
(params['referrer_link'] like '%[%' and (
json_split(params['referrer_link'])[size(json_split(params['referrer_link']))-1]='home')) SELECT partition_date,cl_id,business_id,app_session_id,params['card_id'] as card_id,
group by partition_date,cl_id,business_id,app_session_id,params['card_id'], case when page_name in ('diary_detail','topic_detail') then 'diary'
case when page_name in ('diary_detail','topic_detail') then 'diary' when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post' when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa' when page_name in ('custom_special') then 'special' else null end as page_name,
when page_name in ('custom_special') then 'special' else null end count(1) as service_pv
)a
left join
(
select id,visual_page_id,'special' as page_name
from tl.tl_zx_api_special_pool
where partition_day ={partition_day}
group by id,visual_page_id
)b
on a.business_id=b.visual_page_id and a.page_name=b.page_name
group by partition_date,cl_id,coalesce(b.id,a.business_id),a.page_name
)t7
on t7.partition_date=t3.partition_date
and t7.cl_id=t3.cl_id
and t7.business_id=t3.card_id
and t7.page_name=t3.card_content_type
LEFT JOIN
(--推荐的美购卡片(需要排除作者消费的美购)
SELECT partition_date,cl_id,coalesce(b.id,a.business_id) as business_id,a.page_name,count(1) as recom_wel_pv
FROM
(
SELECT partition_date,cl_id,business_id,app_session_id,params['card_id'] as card_id,
case when page_name in ('diary_detail','topic_detail') then 'diary'
when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
when page_name in ('custom_special') then 'special' else null end as page_name,
count(1) as service_pv
FROM online.bl_hdfs_maidian_updates
WHERE partition_date={partition_day}
AND (action='on_click_card'and params['card_content_type']='service'
or action='on_click_button' and params['button_name']='unfold' and page_name in ('diary_detail','topic_detail','post_detail','user_post_detail','doctor_post_detail')
or action='on_click_button' and params['button_name'] = 'more_recommendations')
AND page_name IN ('diary_detail','topic_detail','post_detail','user_post_detail','doctor_post_detail','question_detail','answer_detail','question_answer_detail','custom_special')
AND (referrer='home' or
(params['referrer_link'] like '%[%' and
json_split(params['referrer_link'])[size(json_split(params['referrer_link']))-1]='home'))
group by partition_date,cl_id,business_id,app_session_id,params['card_id'],
case when page_name in ('diary_detail','topic_detail') then 'diary'
when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
when page_name in ('custom_special') then 'special' else null end
)a
left join
(
select id,visual_page_id,'special' as page_name
from tl.tl_zx_api_special_pool
where partition_day ={partition_day}
group by id,visual_page_id
)b
on a.business_id=b.visual_page_id and a.page_name=b.page_name
group by partition_date,cl_id,coalesce(b.id,a.business_id),a.page_name
)t8
on t8.partition_date=t3.partition_date
and t8.cl_id=t3.cl_id
and t8.business_id=t3.card_id
and t8.page_name=t3.card_content_type
LEFT JOIN
(--推荐的内容卡片
SELECT partition_date,cl_id,coalesce(b.id,a.business_id) as business_id,a.page_name,count(1) as recom_content_pv
FROM
(
SELECT partition_date,cl_id,business_id,app_session_id,params['card_id'] as card_id,
case when page_name in ('diary_detail','topic_detail') then 'diary'
when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
when page_name in ('custom_special') then 'special' else null end as page_name,
count(1) as service_pv
FROM online.bl_hdfs_maidian_updates
WHERE partition_date={partition_day}
AND action='on_click_card'
and params['card_content_type'] in ('qa','diary','user_post','answer')
AND page_name IN ('diary_detail','topic_detail','post_detail','user_post_detail','doctor_post_detail','question_detail','answer_detail','question_answer_detail','custom_special')
AND (referrer='home' or
(params['referrer_link'] like '%[%' and
json_split(params['referrer_link'])[size(json_split(params['referrer_link']))-1]='home'))
group by partition_date,cl_id,business_id,app_session_id,params['card_id'],
case when page_name in ('diary_detail','topic_detail') then 'diary'
when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
when page_name in ('custom_special') then 'special' else null end
)a
left join
(
select id,visual_page_id,'special' as page_name
from tl.tl_zx_api_special_pool
where partition_day ={partition_day}
group by id,visual_page_id
)b
on a.business_id=b.visual_page_id and a.page_name=b.page_name
group by partition_date,cl_id,coalesce(b.id,a.business_id),a.page_name
)t9
on t9.partition_date=t3.partition_date
and t9.cl_id=t3.cl_id
and t9.business_id=t3.card_id
and t9.page_name=t3.card_content_type
LEFT JOIN
(--视频面诊点击
select partition_date,cl_id,coalesce(b.id,a.business_id) as business_id,a.page_name,video_pv
from
(
SELECT partition_date,cl_id,business_id,
case when page_name in ('diary_detail','topic_detail') then 'diary'
when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
when page_name in ('custom_special') then 'special' else null end as page_name,
count(1) as video_pv
FROM online.bl_hdfs_maidian_updates
WHERE partition_date={partition_day}
AND action='on_click_button'
and params['button_name']='video_interview'
AND page_name IN ('diary_detail','topic_detail','post_detail','user_post_detail','doctor_post_detail','question_detail','answer_detail','question_answer_detail','custom_special')
AND (referrer='home' or
(params['referrer_link'] like '%[%' and
json_split(params['referrer_link'])[size(json_split(params['referrer_link']))-1]='home'))
group by partition_date,cl_id,business_id,
case when page_name in ('diary_detail','topic_detail') then 'diary'
when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
when page_name in ('custom_special') then 'special' else null end
)a
left join
(
select id,visual_page_id,'special' as page_name
from tl.tl_zx_api_special_pool
where partition_day ={partition_day}
group by id,visual_page_id
)b
on a.business_id=b.visual_page_id and a.page_name=b.page_name
)t10
on t10.partition_date=t3.partition_date
and t10.cl_id=t3.cl_id
and t10.business_id=t3.card_id
and t10.page_name=t3.card_content_type
LEFT JOIN
(--转诊按钮点击
select partition_date,cl_id,coalesce(b.id,a.business_id) as business_id,a.page_name,referral_pv
from
(
SELECT partition_date,cl_id,business_id,
case when page_name in ('diary_detail','topic_detail') then 'diary'
when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
when page_name in ('custom_special') then 'special' else null end as page_name,
count(1) as referral_pv
FROM online.bl_hdfs_maidian_updates
WHERE partition_date={partition_day}
AND action='on_click_button'
and params['button_name']='referral'
AND page_name IN ('diary_detail','topic_detail','post_detail','user_post_detail','doctor_post_detail','question_detail','answer_detail','question_answer_detail','custom_special')
AND (referrer='home' or
(params['referrer_link'] like '%[%' and
json_split(params['referrer_link'])[size(json_split(params['referrer_link']))-1]='home'))
group by partition_date,cl_id,business_id,
case when page_name in ('diary_detail','topic_detail') then 'diary'
when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
when page_name in ('custom_special') then 'special' else null end
)a
left join
(
select id,visual_page_id,'special' as page_name
from tl.tl_zx_api_special_pool
where partition_day ={partition_day}
group by id,visual_page_id
)b
on a.business_id=b.visual_page_id and a.page_name=b.page_name
)t11
on t11.partition_date=t3.partition_date
and t11.cl_id=t3.cl_id
and t11.business_id=t3.card_id
and t11.page_name=t3.card_content_type
LEFT JOIN
(--从帖子页到帖子页
SELECT partition_date,cl_id,params['referrer_id'] as business_id,
case when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
else null end as page_name,
count(distinct params['business_id'],app_session_id) as post_pv
FROM online.bl_hdfs_maidian_updates FROM online.bl_hdfs_maidian_updates
WHERE partition_date={partition_day} WHERE partition_date='{partition_day}'
AND action='page_view' AND (action='on_click_card'and params['card_content_type']='service'
AND page_name IN ('post_detail','user_post_detail','doctor_post_detail','custom_special') or action='on_click_button' and params['button_name']='unfold' and page_name in ('diary_detail','topic_detail','post_detail','user_post_detail','doctor_post_detail')
AND (json_split(params['referrer_link'])[size(json_split(params['referrer_link']))-1]IN ('post_detail','user_post_detail','doctor_post_detail') or action='on_click_button' and params['button_name'] = 'more_recommendations')
and json_split(params['referrer_link'])[size(json_split(params['referrer_link']))-2]='home') AND page_name IN ('diary_detail','topic_detail','post_detail','user_post_detail','doctor_post_detail','question_detail','answer_detail','question_answer_detail','custom_special')
group by partition_date,cl_id,params['referrer_id'], AND (referrer='home' or
case when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post' (params['referrer_link'] like '%[%' and
else null end json_split(params['referrer_link'])[size(json_split(params['referrer_link']))-1]='home'))
)t12 group by partition_date,cl_id,business_id,app_session_id,params['card_id'],
on t12.partition_date=t3.partition_date case when page_name in ('diary_detail','topic_detail') then 'diary'
and t12.cl_id=t3.cl_id when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
and t12.business_id=t3.card_id when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
and t12.page_name=t3.card_content_type when page_name in ('custom_special') then 'special' else null end
)a
left join left join
(--在帖子页点击帖子 (
SELECT partition_date,cl_id,params['business_id'] as business_id, select id,visual_page_id,'special' as page_name
case when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post' from tl.tl_zx_api_special_pool
else null end as page_name, where partition_day ='{partition_day}'
count(distinct params['card_id'],app_session_id) as post_click_pv group by id,visual_page_id
)b
on a.business_id=b.visual_page_id and a.page_name=b.page_name
group by partition_date,cl_id,coalesce(b.id,a.business_id),a.page_name
)t8
on t8.partition_date=t3.partition_date
and t8.cl_id=t3.cl_id
and t8.business_id=t3.card_id
and t8.page_name=t3.card_content_type
LEFT JOIN
(--推荐的内容卡片
SELECT partition_date,cl_id,coalesce(b.id,a.business_id) as business_id,a.page_name,count(1) as recom_content_pv
FROM
(
SELECT partition_date,cl_id,business_id,app_session_id,params['card_id'] as card_id,
case when page_name in ('diary_detail','topic_detail') then 'diary'
when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
when page_name in ('custom_special') then 'special' else null end as page_name,
count(1) as service_pv
FROM online.bl_hdfs_maidian_updates FROM online.bl_hdfs_maidian_updates
WHERE partition_date={partition_day} WHERE partition_date='{partition_day}'
AND action='on_click_card' AND action='on_click_card'
and params['card_content_type'] in ('user_post') and params['card_content_type'] in ('qa','diary','user_post','answer')
AND page_name IN ('post_detail','user_post_detail','doctor_post_detail') AND page_name IN ('diary_detail','topic_detail','post_detail','user_post_detail','doctor_post_detail','question_detail','answer_detail','question_answer_detail','custom_special')
AND (referrer='home' or AND (referrer='home' or
(params['referrer_link'] like '%[%' and (params['referrer_link'] like '%[%' and
json_split(params['referrer_link'])[size(json_split(params['referrer_link']))-1]='home')) json_split(params['referrer_link'])[size(json_split(params['referrer_link']))-1]='home'))
group by partition_date,cl_id,params['business_id'], group by partition_date,cl_id,business_id,app_session_id,params['card_id'],
case when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post' case when page_name in ('diary_detail','topic_detail') then 'diary'
else null end when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
)t13 when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
on t13.partition_date=t3.partition_date when page_name in ('custom_special') then 'special' else null end
and t13.cl_id=t3.cl_id )a
and t13.business_id=t3.card_id left join
and t13.page_name=t3.card_content_type
LEFT JOIN
( (
select distinct device_id select id,visual_page_id,'special' as page_name
from ML.ML_D_CT_DV_DEVICECLEAN_DIMEN_D from tl.tl_zx_api_special_pool
where PARTITION_DAY = '{partition_day}' where partition_day ='{partition_day}'
AND is_abnormal_device = 'true' group by id,visual_page_id
)dev )b
on t1.device_id=dev.device_id on a.business_id=b.visual_page_id and a.page_name=b.page_name
WHERE dev.device_id is null group by partition_date,cl_id,coalesce(b.id,a.business_id),a.page_name
GROUP BY t1.partition_date,t1.device_os_type,t1.active_type,t2.card_content_type,t2.recommend_type )t9
order by day_id,device_os_type,active_type,card_content_type,recommend_type on t9.partition_date=t3.partition_date
and t9.cl_id=t3.cl_id
and t9.business_id=t3.card_id
and t9.page_name=t3.card_content_type
LEFT JOIN
(--视频面诊点击
select partition_date,cl_id,coalesce(b.id,a.business_id) as business_id,a.page_name,video_pv
from
(
SELECT partition_date,cl_id,business_id,
case when page_name in ('diary_detail','topic_detail') then 'diary'
when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
when page_name in ('custom_special') then 'special' else null end as page_name,
count(1) as video_pv
FROM online.bl_hdfs_maidian_updates
WHERE partition_date='{partition_day}'
AND action='on_click_button'
and params['button_name']='video_interview'
AND page_name IN ('diary_detail','topic_detail','post_detail','user_post_detail','doctor_post_detail','question_detail','answer_detail','question_answer_detail','custom_special')
AND (referrer='home' or
(params['referrer_link'] like '%[%' and
json_split(params['referrer_link'])[size(json_split(params['referrer_link']))-1]='home'))
group by partition_date,cl_id,business_id,
case when page_name in ('diary_detail','topic_detail') then 'diary'
when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
when page_name in ('custom_special') then 'special' else null end
)a
left join
(
select id,visual_page_id,'special' as page_name
from tl.tl_zx_api_special_pool
where partition_day ='{partition_day}'
group by id,visual_page_id
)b
on a.business_id=b.visual_page_id and a.page_name=b.page_name
)t10
on t10.partition_date=t3.partition_date
and t10.cl_id=t3.cl_id
and t10.business_id=t3.card_id
and t10.page_name=t3.card_content_type
LEFT JOIN
(--转诊按钮点击
select partition_date,cl_id,coalesce(b.id,a.business_id) as business_id,a.page_name,referral_pv
from
(
SELECT partition_date,cl_id,business_id,
case when page_name in ('diary_detail','topic_detail') then 'diary'
when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
when page_name in ('custom_special') then 'special' else null end as page_name,
count(1) as referral_pv
FROM online.bl_hdfs_maidian_updates
WHERE partition_date='{partition_day}'
AND action='on_click_button'
and params['button_name']='referral'
AND page_name IN ('diary_detail','topic_detail','post_detail','user_post_detail','doctor_post_detail','question_detail','answer_detail','question_answer_detail','custom_special')
AND (referrer='home' or
(params['referrer_link'] like '%[%' and
json_split(params['referrer_link'])[size(json_split(params['referrer_link']))-1]='home'))
group by partition_date,cl_id,business_id,
case when page_name in ('diary_detail','topic_detail') then 'diary'
when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
when page_name in ('question_detail','answer_detail','question_answer_detail') then 'qa'
when page_name in ('custom_special') then 'special' else null end
)a
left join
(
select id,visual_page_id,'special' as page_name
from tl.tl_zx_api_special_pool
where partition_day ='{partition_day}'
group by id,visual_page_id
)b
on a.business_id=b.visual_page_id and a.page_name=b.page_name
)t11
on t11.partition_date=t3.partition_date
and t11.cl_id=t3.cl_id
and t11.business_id=t3.card_id
and t11.page_name=t3.card_content_type
LEFT JOIN
(--从帖子页到帖子页
SELECT partition_date,cl_id,params['referrer_id'] as business_id,
case when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
else null end as page_name,
count(distinct params['business_id'],app_session_id) as post_pv
FROM online.bl_hdfs_maidian_updates
WHERE partition_date='{partition_day}'
AND action='page_view'
AND page_name IN ('post_detail','user_post_detail','doctor_post_detail','custom_special')
AND (json_split(params['referrer_link'])[size(json_split(params['referrer_link']))-1]IN ('post_detail','user_post_detail','doctor_post_detail')
and json_split(params['referrer_link'])[size(json_split(params['referrer_link']))-2]='home')
group by partition_date,cl_id,params['referrer_id'],
case when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
else null end
)t12
on t12.partition_date=t3.partition_date
and t12.cl_id=t3.cl_id
and t12.business_id=t3.card_id
and t12.page_name=t3.card_content_type
left join
(--在帖子页点击帖子
SELECT partition_date,cl_id,params['business_id'] as business_id,
case when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
else null end as page_name,
count(distinct params['card_id'],app_session_id) as post_click_pv
FROM online.bl_hdfs_maidian_updates
WHERE partition_date='{partition_day}'
AND action='on_click_card'
and params['card_content_type'] in ('user_post')
AND page_name IN ('post_detail','user_post_detail','doctor_post_detail')
AND (referrer='home' or
(params['referrer_link'] like '%[%' and
json_split(params['referrer_link'])[size(json_split(params['referrer_link']))-1]='home'))
group by partition_date,cl_id,params['business_id'],
case when page_name in ('post_detail','user_post_detail','doctor_post_detail') then 'user_post'
else null end
)t13
on t13.partition_date=t3.partition_date
and t13.cl_id=t3.cl_id
and t13.business_id=t3.card_id
and t13.page_name=t3.card_content_type
LEFT JOIN
(
select distinct device_id
from ML.ML_D_CT_DV_DEVICECLEAN_DIMEN_D
where PARTITION_DAY = '{partition_day}'
AND is_abnormal_device = 'true'
)dev
on t1.partition_date=dev.partition_date and t1.device_id=dev.device_id
WHERE dev.device_id is null
GROUP BY t1.partition_date,t1.device_os_type,t1.active_type,t2.card_content_type,t2.recommend_type
order by day_id,device_os_type,active_type,card_content_type,recommend_type
""".format(partition_day=today_str) """.format(partition_day=today_str)
ctr_df = spark.sql(ctr_sql) ctr_df = spark.sql(ctr_sql)
ctr_df.createOrReplaceTempView("temp_ctr") ctr_df.createOrReplaceTempView("temp_ctr")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment