Commit e592aab7 authored by sheteng's avatar sheteng

迁移sql

parent 32300d80
Pipeline #2123 failed with stages
in 0 seconds
# appsflyer_advert_ck
新广告广告后台计算
数据迁移
CREATE TABLE adv_appsflyer.appsflyer_metrics
(
`data_date` Int64 COMMENT '日期 20190228',
`data_hour` Int64 COMMENT '小时 13',
`time_zone` String COMMENT '时区 +0900',
`region` String DEFAULT 'KR' COMMENT '韩国KR,
香港 HK,
台湾 TW,
其它:-1,或者其它值',
`platform` String COMMENT '平台 Android|IOS',
`game_id` String COMMENT '游戏ID bundle_id,com.edgames.new19gp',
`channel` String DEFAULT '-1',
`media_source` String COMMENT '媒体平台 googleadwords_int',
`campaign_id` String COMMENT '广告系列ID 23843308705120641',
`ad_set_id` String COMMENT '广告组|计划ID 23843308705230641',
`ad_id` String COMMENT '广告ID 23843308708070641',
`data_type` Int8 DEFAULT '0' COMMENT '1.新增 2.再营销 3.预注册',
`data_activation` Int64 DEFAULT '0' COMMENT '激活数 按唯一设备去重 ',
`data_register` Int64 DEFAULT '0' COMMENT '注册数 按唯一用户去重',
`data_day_act_register` Int64 DEFAULT '0' COMMENT '当日激活 并且当日注册数',
`data_device_register` Int64 DEFAULT '0' COMMENT '设备注册数',
`data_create_role` Int32 DEFAULT '0' COMMENT '创角数',
`data_day_register_create` Int32 DEFAULT '0' COMMENT '当日注册 并且当日创角数',
`data_active_day_dau` Int32 DEFAULT '0' COMMENT '当日登录用户,排除当日注册用户',
`data_active_2day` Int64 DEFAULT '0' COMMENT '次日活跃|留存',
`data_active_3day` Int64 DEFAULT '0' COMMENT '3日活跃|留存',
`data_active_7day` Int64 DEFAULT '0' COMMENT '7日活跃|留存',
`data_active_15day` Int64 DEFAULT '0' COMMENT '15日活跃|留存',
`data_active_30day` Int64 DEFAULT '0' COMMENT '30日活跃|留存'
)
ENGINE = SummingMergeTree()
PARTITION BY intDiv(data_date , 100)
ORDER BY (data_date,
data_hour,
time_zone,
region,
platform,
game_id,
channel,
media_source,
campaign_id,
ad_set_id,
ad_id,
data_type)
SETTINGS index_granularity = 8192
INSERT into appsflyer_metrics
select data_date,data_hour,time_zone,region,platform,game_id,channel,media_source,campaign_id,ad_set_id, ad_id,data_type,data_activation,data_register,
data_day_act_register,data_device_register,data_create_role,data_day_register_create,data_active_day_dau,data_active_2day,data_active_3day,
data_active_7day,data_active_15day,data_active_30day
FROM mysql('10.3.15.213:3306', 'adv_appsflyer_new', 'appsflyer_metrics', 'appsflyer', 'Hs*9Ds1&s')
CREATE TABLE adv_appsflyer.appsflyer_pay_record
(
`did` String DEFAULT '-1',
`uid` String COMMENT '用户ID,
appsflyer_device_id',
`game_id` String COMMENT '游戏ID bundle_id com.edgames.new19gp',
`region` String DEFAULT 'KR' COMMENT '韩国KR',
`platform` String COMMENT '平台 Android|IOS',
`media_source` String COMMENT '媒体平台 googleadwords_int',
`campaign_id` String COMMENT '广告系列ID 23843308705120641',
`ad_set_id` String DEFAULT '-1' COMMENT '广告组|计划ID 23843308705230641',
`ad_id` String DEFAULT '-1' COMMENT '广告ID 23843308708070641',
`channel` Nullable(String) COMMENT 'channel',
`currency` String DEFAULT 'KRW' COMMENT '货币类型',
`data_type` Int8 ,
`money` Float64 COMMENT '支付金额',
`order_no` String COMMENT '订单编号',
`pay_time` DateTime COMMENT '支付时间 2019-02-28 00:07:06',
`activation_time` DateTime COMMENT '激活时间',
`reg_time` Nullable(DateTime) COMMENT '注册时间',
`time_zone` String DEFAULT '+0900' COMMENT '时区'
)
ENGINE = MergeTree
PARTITION BY toYYYYMM(pay_time)
ORDER BY (uid,
game_id,
pay_time,
platform,
media_source,
campaign_id,
ad_set_id,
ad_id,
order_no,)
SETTINGS index_granularity = 8192
UPDATE appsflyer_pay_record t1,appsflyer_activation_devices t2 set t1.activation_time = t2.activation_time WHERE t1.uid = t2.uid
INSERT into appsflyer_pay_record select
did,uid,game_id,region,platform,media_source,campaign_id,ad_set_id,ad_id,channel,currency,'1',money,order_no,pay_time,
activation_time, reg_time,time_zone
FROM mysql('10.3.15.213:3306', 'adv_appsflyer_new', 'appsflyer_pay_record', 'appsflyer', 'Hs*9Ds1&s') WHERE activation_time is NOT NULL AND toDate(activation_time) is NOT NULL;
//物化视图 ltv
CREATE MATERIALIZED VIEW IF NOT EXISTS appsflyer_order_accumulative_view
ENGINE = SummingMergeTree
PARTITION BY game_id
ORDER BY (ds, game_id, platform, media_source, campaign_id, ad_set_id, ad_id, currency,region)
POPULATE
AS SELECT toYYYYMMDD(activation_time) as ds, game_id, platform, media_source, campaign_id, ad_set_id, ad_id, currency,region,
sum( IF(dateDiff('day',activation_time,now())>=0 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)=0 and money IS NOT NULL ,money ,0 )) as day0_sum ,
sum( IF(dateDiff('day',activation_time,now())>=1 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=1 and money IS NOT NULL ,money ,0 )) as day1_sum ,
sum( IF(dateDiff('day',activation_time,now())>=2 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=2 and money IS NOT NULL ,money ,0 )) as day2_sum ,
sum( IF(dateDiff('day',activation_time,now())>=3 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=3 and money IS NOT NULL ,money ,0 )) as day3_sum ,
sum( IF(dateDiff('day',activation_time,now())>=4 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=4 and money IS NOT NULL ,money ,0 )) as day4_sum ,
sum( IF(dateDiff('day',activation_time,now())>=5 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=5 and money IS NOT NULL ,money ,0 )) as day5_sum ,
sum( IF(dateDiff('day',activation_time,now())>=6 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=6 and money IS NOT NULL ,money ,0 )) as day6_sum ,
sum( IF(dateDiff('day',activation_time,now())>=7 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=7 and money IS NOT NULL ,money ,0 )) as day7_sum ,
sum( IF(dateDiff('day',activation_time,now())>=8 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=8 and money IS NOT NULL ,money ,0 )) as day8_sum ,
sum( IF(dateDiff('day',activation_time,now())>=9 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=9 and money IS NOT NULL ,money ,0 )) as day9_sum ,
sum( IF(dateDiff('day',activation_time,now())>=10 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=10 and money IS NOT NULL ,money ,0 )) as day10_sum ,
sum( IF(dateDiff('day',activation_time,now())>=11 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=11 and money IS NOT NULL ,money ,0 )) as day11_sum ,
sum( IF(dateDiff('day',activation_time,now())>=12 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=12 and money IS NOT NULL ,money ,0 )) as day12_sum ,
sum( IF(dateDiff('day',activation_time,now())>=13 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=13 and money IS NOT NULL ,money ,0 )) as day13_sum ,
sum( IF(dateDiff('day',activation_time,now())>=14 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=14 and money IS NOT NULL ,money ,0 )) as day14_sum ,
sum( IF(dateDiff('day',activation_time,now())>=15 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=15 and money IS NOT NULL ,money ,0 )) as day15_sum ,
sum( IF(dateDiff('day',activation_time,now())>=20 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=20 and money IS NOT NULL ,money ,0 )) as day20_sum ,
sum( IF(dateDiff('day',activation_time,now())>=25 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=25 and money IS NOT NULL ,money ,0 )) as day25_sum ,
sum( IF(dateDiff('day',activation_time,now())>=30 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=30 and money IS NOT NULL ,money ,0 )) as day30_sum ,
sum( IF(dateDiff('day',activation_time,now())>=35 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=35 and money IS NOT NULL ,money ,0 )) as day35_sum ,
sum( IF(dateDiff('day',activation_time,now())>=40 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=40 and money IS NOT NULL ,money ,0 )) as day40_sum ,
sum( IF(dateDiff('day',activation_time,now())>=45 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=45 and money IS NOT NULL ,money ,0 )) as day45_sum ,
sum( IF(dateDiff('day',activation_time,now())>=50 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=50 and money IS NOT NULL ,money ,0 )) as day50_sum ,
sum( IF(dateDiff('day',activation_time,now())>=55 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=55 and money IS NOT NULL ,money ,0 )) as day55_sum ,
sum( IF(dateDiff('day',activation_time,now())>=60 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=60 and money IS NOT NULL ,money ,0 )) as day60_sum ,
sum( IF(dateDiff('day',activation_time,now())>=65 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=65 and money IS NOT NULL ,money ,0 )) as day65_sum ,
sum( IF(dateDiff('day',activation_time,now())>=70 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=70 and money IS NOT NULL ,money ,0 )) as day70_sum ,
sum( IF(dateDiff('day',activation_time,now())>=75 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=75 and money IS NOT NULL ,money ,0 )) as day75_sum ,
sum( IF(dateDiff('day',activation_time,now())>=80 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=80 and money IS NOT NULL ,money ,0 )) as day80_sum ,
sum( IF(dateDiff('day',activation_time,now())>=85 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=85 and money IS NOT NULL ,money ,0 )) as day85_sum ,
sum( IF(dateDiff('day',activation_time,now())>=90 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=90 and money IS NOT NULL ,money ,0 )) as day90_sum ,
sum( IF(dateDiff('day',activation_time,now())>=120 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=120 and money IS NOT NULL ,money ,0 )) as day120_sum ,
sum( IF(dateDiff('day',activation_time,now())>=150 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=150 and money IS NOT NULL ,money ,0 )) as day150_sum ,
sum( IF(dateDiff('day',activation_time,now())>=180 and activation_time<=pay_time and dateDiff('day',activation_time,pay_time)<=180 and money IS NOT NULL ,money ,0 )) as day180_sum ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=0 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)=0 and uid is not null,uid ,null )) as day0_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=1 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=1 and uid is not null,uid ,null )) as day1_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=2 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=2 and uid is not null,uid ,null )) as day2_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=3 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=3 and uid is not null,uid ,null )) as day3_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=4 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=4 and uid is not null,uid ,null )) as day4_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=5 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=5 and uid is not null,uid ,null )) as day5_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=6 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=6 and uid is not null,uid ,null )) as day6_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=7 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=7 and uid is not null,uid ,null )) as day7_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=8 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=8 and uid is not null,uid ,null )) as day8_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=9 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=9 and uid is not null,uid ,null )) as day9_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=10 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=10 and uid is not null,uid ,null )) as day10_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=11 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=11 and uid is not null,uid ,null )) as day11_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=12 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=12 and uid is not null,uid ,null )) as day12_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=13 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=13 and uid is not null,uid ,null )) as day13_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=14 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=14 and uid is not null,uid ,null )) as day14_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=15 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=15 and uid is not null,uid ,null )) as day15_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=20 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=20 and uid is not null,uid ,null )) as day20_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=25 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=25 and uid is not null,uid ,null )) as day25_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=30 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=30 and uid is not null,uid ,null )) as day30_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=35 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=35 and uid is not null,uid ,null )) as day35_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=40 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=40 and uid is not null,uid ,null )) as day40_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=45 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=45 and uid is not null,uid ,null )) as day45_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=50 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=50 and uid is not null,uid ,null )) as day50_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=55 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=55 and uid is not null,uid ,null )) as day55_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=60 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=60 and uid is not null,uid ,null )) as day60_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=65 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=65 and uid is not null,uid ,null )) as day65_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=70 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=70 and uid is not null,uid ,null )) as day70_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=75 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=75 and uid is not null,uid ,null )) as day75_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=80 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=80 and uid is not null,uid ,null )) as day80_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=85 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=85 and uid is not null,uid ,null )) as day85_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=90 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=90 and uid is not null,uid ,null )) as day90_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=120 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=120 and uid is not null,uid ,null )) as day120_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=150 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=150 and uid is not null,uid ,null )) as day150_num ,
count(DISTINCT IF(DATEDIFF('day',activation_time,now())>=180 and activation_time<=pay_time and DATEDIFF('day',activation_time,pay_time)<=180 and uid is not null,uid ,null )) as day180_num ,
sum(money) as day_now_sum,
count(DISTINCT(uid)) as day_now_num
from appsflyer_pay_record
GROUP BY toYYYYMMDD(activation_time), game_id, platform, media_source, campaign_id, ad_set_id, ad_id, currency ,region
//新的指标表
CREATE TABLE adv_appsflyer.appsflyer_metrics_detail
(
`uid` String COMMENT '用户id',
`data_date` Int64 COMMENT '日期 20190228',
`data_hour` Int16 COMMENT '小时 13',
`time_zone` String COMMENT '时区 +0900',
`region` String DEFAULT 'KR' COMMENT '韩国KR,
香港 HK,
台湾 TW,
其它:-1,或者其它值',
`platform` String COMMENT '平台 Android|IOS',
`game_id` String COMMENT '游戏ID bundle_id,
com.edgames.new19gp',
`channel` String DEFAULT '-1',
`media_source` String COMMENT '媒体平台 googleadwords_int',
`campaign_id` String COMMENT '广告系列ID 23843308705120641',
`ad_set_id` String COMMENT '广告组|计划ID 23843308705230641',
`ad_id` String COMMENT '广告ID 23843308708070641',
`data_type` Int8 DEFAULT '0' COMMENT '1.新增 2.再营销 3.预注册',
`metric_name` String COMMENT '指标名称',
`metric_value` Int64 COMMENT '指标值'
)
ENGINE = MergeTree
PARTITION BY intDiv(data_date , 100)
ORDER BY ( uid,
data_date,
data_hour,
time_zone,
region,
platform,
game_id,
channel,
media_source,
campaign_id,
ad_set_id,
ad_id,
data_type,
metric_name)
SETTINGS index_granularity = 8192
//转移数据 列转行
INSERT into appsflyer_metrics_detail
select -1 as uid ,data_date,data_hour,time_zone,region,platform,game_id,channel,media_source,campaign_id,ad_set_id, ad_id,data_type,'data_view',data_view
FROM mysql('10.3.15.213:3306', 'adv_appsflyer_new', 'appsflyer_metrics', 'appsflyer', 'Hs*9Ds1&s')
UNION ALL
select -1 as uid ,data_date,data_hour,time_zone,region,platform,game_id,channel,media_source,campaign_id,ad_set_id, ad_id,data_type,'data_click',data_click
FROM mysql('10.3.15.213:3306', 'adv_appsflyer_new', 'appsflyer_metrics', 'appsflyer', 'Hs*9Ds1&s')
UNION ALL
select -1 as uid ,data_date,data_hour,time_zone,region,platform,game_id,channel,media_source,campaign_id,ad_set_id, ad_id,data_type,'data_activation',data_activation
FROM mysql('10.3.15.213:3306', 'adv_appsflyer_new', 'appsflyer_metrics', 'appsflyer', 'Hs*9Ds1&s')
UNION ALL
select -1 as uid ,data_date,data_hour,time_zone,region,platform,game_id,channel,media_source,campaign_id,ad_set_id, ad_id,data_type,'data_register',data_register
FROM mysql('10.3.15.213:3306', 'adv_appsflyer_new', 'appsflyer_metrics', 'appsflyer', 'Hs*9Ds1&s')
UNION ALL
select -1 as uid ,data_date,data_hour,time_zone,region,platform,game_id,channel,media_source,campaign_id,ad_set_id, ad_id,data_type,'data_day_act_register',data_day_act_register
FROM mysql('10.3.15.213:3306', 'adv_appsflyer_new', 'appsflyer_metrics', 'appsflyer', 'Hs*9Ds1&s')
UNION ALL
select -1 as uid ,data_date,data_hour,time_zone,region,platform,game_id,channel,media_source,campaign_id,ad_set_id, ad_id,data_type,'data_device_register',data_device_register
FROM mysql('10.3.15.213:3306', 'adv_appsflyer_new', 'appsflyer_metrics', 'appsflyer', 'Hs*9Ds1&s')
UNION ALL
select -1 as uid ,data_date,data_hour,time_zone,region,platform,game_id,channel,media_source,campaign_id,ad_set_id, ad_id,data_type,'data_create_role',data_create_role
FROM mysql('10.3.15.213:3306', 'adv_appsflyer_new', 'appsflyer_metrics', 'appsflyer', 'Hs*9Ds1&s')
UNION ALL
select -1 as uid ,data_date,data_hour,time_zone,region,platform,game_id,channel,media_source,campaign_id,ad_set_id, ad_id,data_type,'data_day_register_create',data_day_register_create
FROM mysql('10.3.15.213:3306', 'adv_appsflyer_new', 'appsflyer_metrics', 'appsflyer', 'Hs*9Ds1&s')
UNION ALL
select -1 as uid ,data_date,data_hour,time_zone,region,platform,game_id,channel,media_source,campaign_id,ad_set_id, ad_id,data_type,'data_active_day_dau',data_active_day_dau
FROM mysql('10.3.15.213:3306', 'adv_appsflyer_new', 'appsflyer_metrics', 'appsflyer', 'Hs*9Ds1&s')
UNION ALL
select -1 as uid ,data_date,data_hour,time_zone,region,platform,game_id,channel,media_source,campaign_id,ad_set_id, ad_id,data_type,'re_engagement',re_engagement
FROM mysql('10.3.15.213:3306', 'adv_appsflyer_new', 'appsflyer_metrics', 'appsflyer', 'Hs*9Ds1&s')
UNION ALL
select -1 as uid ,data_date,data_hour,time_zone,region,platform,game_id,channel,media_source,campaign_id,ad_set_id, ad_id,data_type,'re_attribution',re_attribution
FROM mysql('10.3.15.213:3306', 'adv_appsflyer_new', 'appsflyer_metrics', 'appsflyer', 'Hs*9Ds1&s');
//物化视图 metric
CREATE MATERIALIZED VIEW IF NOT EXISTS appsflyer_metric_view
ENGINE = AggregatingMergeTree
PARTITION BY intDiv(data_date , 100)
ORDER BY (data_date,data_hour,time_zone,region,platform,game_id,channel,media_source,campaign_id,ad_set_id, ad_id,data_type)
POPULATE
AS select data_date,data_hour,time_zone,region,platform,game_id,channel,media_source,campaign_id,ad_set_id, ad_id,data_type,
SUM(IF(metric_name='data_view',metric_value,0)) AS data_view,
SUM(IF(metric_name='data_click',metric_value,0)) AS data_click,
SUM(IF(metric_name='data_activation',metric_value,0)) AS data_activation,
SUM(IF(metric_name='data_register',metric_value,0)) AS data_register,
SUM(IF(metric_name='data_day_act_register',metric_value,0)) AS data_day_act_register,
SUM(IF(metric_name='data_device_register',metric_value,0)) AS data_device_register,
SUM(IF(metric_name='data_create_role',metric_value,0)) AS data_create_role,
SUM(IF(metric_name='data_day_register_create',metric_value,0)) AS data_day_register_create,
SUM(IF(metric_name='data_active_day_dau',metric_value,0)) AS data_active_day_dau,
SUM(IF(metric_name='re_engagement',metric_value,0)) AS re_engagement,
SUM(IF(metric_name='re_attribution',metric_value,0)) AS re_attribution
from appsflyer_metrics_detail
group by data_date,data_hour,time_zone,region,platform,game_id,channel,media_source,campaign_id,ad_set_id, ad_id,data_type
// 激活表
CREATE TABLE `appsflyer_activation_devices` (
`platform` String COMMENT '平台 Android|IOS',
`did` String COMMENT '设备ID IMEI|IDFA',
`uid` String DEFAULT '-1' COMMENT 'appfly device id',
`region` String DEFAULT 'KR' COMMENT '韩国KR, 香港 HK, 台湾 TW, 其它:-1,或者其它值',
`game_id` String COMMENT '游戏ID bundle_id com.edgames.new19gp',
`media_source` String COMMENT '媒体平台 googleadwords_int',
`campaign_id` String COMMENT '广告系列ID 23843308705120641',
`ad_set_id` String DEFAULT '-1' COMMENT '广告组|计划ID 23843308705230641',
`ad_id` String DEFAULT '-1' COMMENT '广告ID 23843308708070641',
`ip` String DEFAULT '' COMMENT 'IP地址',
`time_zone` String DEFAULT '+0900' COMMENT '时区',
`event_type` String COMMENT '类型',
`event_time` DateTime COMMENT '时间'
)
ENGINE = ReplacingMergeTree()
PARTITION BY toYYYYMM(event_time)
ORDER BY (`platform`,`game_id`,`uid`,`event_type`)
SETTINGS index_granularity = 8192
//激活表迁移数据
INSERT into appsflyer_activation_devices
select platform,did,uid,region,game_id,media_source,campaign_id,ad_set_id,ad_id,'',time_zone,'activation',reg_time
FROM mysql('10.3.15.213:3306', 'adv_appsflyer_new', 'appsflyer_register_account', 'appsflyer', 'Hs*9Ds1&s') WHERE reg_time is NOT NULL;
INSERT into appsflyer_activation_devices
select platform,did,uid,region,game_id,media_source,campaign_id,ad_set_id,ad_id,ip,time_zone,'activation',activation_time
FROM mysql('10.3.15.213:3306', 'adv_appsflyer_new', 'appsflyer_activation_devices', 'appsflyer', 'Hs*9Ds1&s');
INSERT into appsflyer_activation_devices
select platform,did,uid,region,game_id,media_source,campaign_id,ad_set_id,ad_id,ip,time_zone,'activation',retargeting_time
FROM mysql('10.3.15.213:3306', 'adv_appsflyer_new', 'appsflyer_activation_devices', 'appsflyer', 'Hs*9Ds1&s') WHERE retargeting_time is NOT NULL;
INSERT into appsflyer_activation_devices
select platform,did,uid,region,game_id,media_source,campaign_id,ad_set_id,ad_id,'',time_zone,'register',reg_time
FROM mysql('10.3.15.213:3306', 'adv_appsflyer_new', 'appsflyer_register_account', 'appsflyer', 'Hs*9Ds1&s') WHERE reg_time is NOT NULL;
INSERT into appsflyer_activation_devices
select platform,did,uid,region,game_id,media_source,campaign_id,ad_set_id,ad_id,'',time_zone,'pauchase',pay_time
FROM mysql('10.3.15.213:3306', 'adv_appsflyer_new', 'appsflyer_pay_record', 'appsflyer', 'Hs*9Ds1&s') WHERE pay_time is NOT NULL;
// 留存表
CREATE TABLE `appsflyer_retention` (
`data_date` Int64 COMMENT '分析时间',
`game_id` String DEFAULT '0' COMMENT 'appid',
`platform` String COMMENT '平台',
`media_source` String COMMENT '媒体平台 googleadwords_int',
`campaign_id` String COMMENT '广告系列ID 23843308705120641',
`region` String DEFAULT 'KR' COMMENT '韩国KR, 香港 HK, 台湾 TW, 其它:-1,或者其它值',
`ad_set_id` String DEFAULT '-1' COMMENT '广告组|计划ID 23843308705230641',
`ad_id` String DEFAULT '-1' COMMENT '广告ID 23843308708070641',
`currency` String COMMENT '货币类型',
`register_num` Int64 DEFAULT '0' COMMENT '注册人数',
`retention_day1` Int64 DEFAULT '0' COMMENT '1日留存',
`retention_day2` Int64 DEFAULT '0' COMMENT '2日留存',
`retention_day3` Int64 DEFAULT '0' COMMENT '3日留存',
`retention_day4` Int64 DEFAULT '0' COMMENT '4日留存',
`retention_day5` Int64 DEFAULT '0' COMMENT '5日留存',
`retention_day6` Int64 DEFAULT '0' COMMENT '6日留存',
`retention_day7` Int64 DEFAULT '0' COMMENT '7日留存',
`retention_day8` Int64 DEFAULT '0' COMMENT '8日留存',
`retention_day9` Int64 DEFAULT '0' COMMENT '9日留存',
`retention_day10` Int64 DEFAULT '0' COMMENT '10日留存',
`retention_day11` Int64 DEFAULT '0' COMMENT '11日留存',
`retention_day12` Int64 DEFAULT '0' COMMENT '12日留存',
`retention_day13` Int64 DEFAULT '0' COMMENT '13日留存',
`retention_day14` Int64 DEFAULT '0' COMMENT '14日留存',
`retention_day15` Int64 DEFAULT '0' COMMENT '15日留存',
`retention_day16` Int64 DEFAULT '0' COMMENT '16日留存',
`retention_day17` Int64 DEFAULT '0' COMMENT '17日留存',
`retention_day18` Int64 DEFAULT '0' COMMENT '18日留存',
`retention_day19` Int64 DEFAULT '0' COMMENT '19日留存',
`retention_day20` Int64 DEFAULT '0' COMMENT '20日留存',
`retention_day21` Int64 DEFAULT '0' COMMENT '21日留存',
`retention_day22` Int64 DEFAULT '0' COMMENT '22日留存',
`retention_day23` Int64 DEFAULT '0' COMMENT '23日留存',
`retention_day24` Int64 DEFAULT '0' COMMENT '24日留存',
`retention_day25` Int64 DEFAULT '0' COMMENT '25日留存',
`retention_day26` Int64 DEFAULT '0' COMMENT '26日留存',
`retention_day27` Int64 DEFAULT '0' COMMENT '27日留存',
`retention_day28` Int64 DEFAULT '0' COMMENT '28日留存',
`retention_day29` Int64 DEFAULT '0' COMMENT '29日留存',
`retention_day30` Int64 DEFAULT '0' COMMENT '30日留存',
`retention_day35` Int64 DEFAULT '0' COMMENT '35日留存',
`retention_day40` Int64 DEFAULT '0' COMMENT '40日留存',
`retention_day45` Int64 DEFAULT '0' COMMENT '45日留存',
`retention_day50` Int64 DEFAULT '0' COMMENT '50日留存',
`retention_day55` Int64 DEFAULT '0' COMMENT '55日留存',
`retention_day60` Int64 DEFAULT '0' COMMENT '60日留存',
`retention_day65` Int64 DEFAULT '0' COMMENT '65日留存',
`retention_day70` Int64 DEFAULT '0' COMMENT '70日留存',
`retention_day75` Int64 DEFAULT '0' COMMENT '75日留存',
`retention_day80` Int64 DEFAULT '0' COMMENT '80日留存',
`retention_day85` Int64 DEFAULT '0' COMMENT '85日留存',
`retention_day90` Int64 DEFAULT '0' COMMENT '90日留存',
`retention_day120` Int64 DEFAULT '0',
`retention_day150` Int64 DEFAULT '0',
`retention_day180` Int64 DEFAULT '0'
) ENGINE=SummingMergeTree
PARTITION BY intDiv(data_date , 100)
order by(`data_date`,`game_id`,`media_source`,`campaign_id`,`ad_set_id`,`ad_id`,`platform`,`currency`,`region`)
SETTINGS index_granularity = 8192
//留存迁移数据
//留存迁移数据
INSERT into appsflyer_retention
select
`ds` as data_date ,
`game_id` ,
`platform`,
`media_source` ,
`campaign_id` ,
`region` ,
`ad_set_id` ,
`ad_id` ,
`currency` ,
`register_num`,
`retention_day1` ,
`retention_day2` ,
`retention_day3` ,
`retention_day4` ,
`retention_day5` ,
`retention_day6` ,
`retention_day7` ,
`retention_day8` ,
`retention_day9` ,
`retention_day10`,
`retention_day11`,
`retention_day12`,
`retention_day13`,
`retention_day14`,
`retention_day15`,
`retention_day16`,
`retention_day17`,
`retention_day18`,
`retention_day19`,
`retention_day20`,
`retention_day21`,
`retention_day22`,
`retention_day23`,
`retention_day24`,
`retention_day25`,
`retention_day26`,
`retention_day27`,
`retention_day28`,
`retention_day29`,
`retention_day30`,
`retention_day35`,
`retention_day40`,
`retention_day45`,
`retention_day50`,
`retention_day55`,
`retention_day60`,
`retention_day65`,
`retention_day70`,
`retention_day75`,
`retention_day80`,
`retention_day85`,
`retention_day90`,
`retention_day120`,
`retention_day150`,
`retention_day180`
FROM mysql('10.3.15.213:3306', 'adv_appsflyer_new', 'appsflyer_order_accumulative', 'appsflyer', 'Hs*9Ds1&s')
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