Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
Amazon-Selection-Data
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abel_cjy
Amazon-Selection-Data
Commits
f154543e
Commit
f154543e
authored
Aug 14, 2026
by
chenyuanjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
流量选品月-Doris历史数据修复与hive一致
parent
e3e58132
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
121 deletions
+34
-121
dwt_flow_asin_month.py
Pyspark_job/doris_handle/dwt_flow_asin_month.py
+34
-121
No files found.
Pyspark_job/doris_handle/dwt_flow_asin_month.py
View file @
f154543e
...
@@ -288,12 +288,13 @@ def read_and_normalize_month_data(spark, site_name, date_info):
...
@@ -288,12 +288,13 @@ def read_and_normalize_month_data(spark, site_name, date_info):
asin_size_type, asin_rating_type, asin_site_name_type, asin_weight_type,
asin_size_type, asin_rating_type, asin_site_name_type, asin_weight_type,
asin_ao_val_type, asin_rank_type, asin_price_type,
asin_ao_val_type, asin_rank_type, asin_price_type,
asin_quantity_variation_type, package_quantity,
asin_quantity_variation_type, package_quantity,
is_movie_label, is_brand_label,
is_movie_label, is_brand_label,
is_alarm_brand,
asin_crawl_date,
asin_crawl_date,
category_first_id, category_id, desc_category_first_id,
category_first_id, category_id, desc_category_first_id,
first_category_rank, current_category_rank,
first_category_rank, current_category_rank,
asin_weight_ratio,
asin_weight_ratio,
seller_country_name,
seller_country_name,
asin_type,
asin_bought_month,
asin_bought_month,
asin_lqs_rating, asin_lqs_rating_detail,
asin_lqs_rating, asin_lqs_rating_detail,
asin_lob_info, is_contains_lob_info,
asin_lob_info, is_contains_lob_info,
...
@@ -411,6 +412,7 @@ def read_and_normalize_month_data(spark, site_name, date_info):
...
@@ -411,6 +412,7 @@ def read_and_normalize_month_data(spark, site_name, date_info):
F
.
col
(
'package_quantity'
)
.
cast
(
'int'
)
.
alias
(
'package_quantity'
),
F
.
col
(
'package_quantity'
)
.
cast
(
'int'
)
.
alias
(
'package_quantity'
),
F
.
col
(
'is_movie_label'
)
.
cast
(
'tinyint'
)
.
alias
(
'is_movie_label'
),
F
.
col
(
'is_movie_label'
)
.
cast
(
'tinyint'
)
.
alias
(
'is_movie_label'
),
F
.
col
(
'is_brand_label'
)
.
cast
(
'tinyint'
)
.
alias
(
'is_brand_label'
),
F
.
col
(
'is_brand_label'
)
.
cast
(
'tinyint'
)
.
alias
(
'is_brand_label'
),
F
.
col
(
'is_alarm_brand'
)
.
cast
(
'int'
)
.
alias
(
'is_alarm_brand'
),
# ===== 分类信息 =====
# ===== 分类信息 =====
_norm_dt
(
'asin_crawl_date'
)
.
alias
(
'asin_crawl_date'
),
_norm_dt
(
'asin_crawl_date'
)
.
alias
(
'asin_crawl_date'
),
F
.
col
(
'category_first_id'
),
F
.
col
(
'category_first_id'
),
...
@@ -420,6 +422,7 @@ def read_and_normalize_month_data(spark, site_name, date_info):
...
@@ -420,6 +422,7 @@ def read_and_normalize_month_data(spark, site_name, date_info):
F
.
col
(
'current_category_rank'
)
.
cast
(
'int'
)
.
alias
(
'current_category_rank'
),
F
.
col
(
'current_category_rank'
)
.
cast
(
'int'
)
.
alias
(
'current_category_rank'
),
F
.
round
(
F
.
col
(
'asin_weight_ratio'
)
.
cast
(
'double'
),
4
)
.
cast
(
'decimal(20,4)'
)
.
alias
(
'asin_weight_ratio'
),
F
.
round
(
F
.
col
(
'asin_weight_ratio'
)
.
cast
(
'double'
),
4
)
.
cast
(
'decimal(20,4)'
)
.
alias
(
'asin_weight_ratio'
),
F
.
col
(
'seller_country_name'
)
.
alias
(
'site_name'
),
F
.
col
(
'seller_country_name'
)
.
alias
(
'site_name'
),
F
.
col
(
'asin_type'
)
.
cast
(
'tinyint'
)
.
alias
(
'asin_type'
),
# ===== 月销及母体信息 =====
# ===== 月销及母体信息 =====
F
.
col
(
'asin_bought_month'
)
.
cast
(
'int'
)
.
alias
(
'asin_bought_month'
),
F
.
col
(
'asin_bought_month'
)
.
cast
(
'int'
)
.
alias
(
'asin_bought_month'
),
F
.
round
(
F
.
col
(
'asin_lqs_rating'
)
.
cast
(
'double'
),
1
)
.
cast
(
'decimal(20,1)'
)
.
alias
(
'asin_lqs_rating'
),
F
.
round
(
F
.
col
(
'asin_lqs_rating'
)
.
cast
(
'double'
),
1
)
.
cast
(
'decimal(20,1)'
)
.
alias
(
'asin_lqs_rating'
),
...
@@ -468,9 +471,9 @@ def write_dwt_month_table(df_save, doris_table):
...
@@ -468,9 +471,9 @@ def write_dwt_month_table(df_save, doris_table):
"bsr_orders_rise, bsr_orders_mom, bsr_orders_yoy, sales_rise, sales_mom, sales_yoy, "
"bsr_orders_rise, bsr_orders_mom, bsr_orders_yoy, sales_rise, sales_mom, sales_yoy, "
"variation_rise, variation_mom, variation_yoy, bought_month_mom, bought_month_yoy, "
"variation_rise, variation_mom, variation_yoy, bought_month_mom, bought_month_yoy, "
"size_type, rating_type, site_name_type, weight_type, ao_val_type, rank_type, price_type, "
"size_type, rating_type, site_name_type, weight_type, ao_val_type, rank_type, price_type, "
"quantity_variation_type, package_quantity, is_movie_label, is_brand_label, "
"quantity_variation_type, package_quantity, is_movie_label, is_brand_label,
is_alarm_brand,
"
"asin_crawl_date, category_first_id, category_id, desc_category_first_id, "
"asin_crawl_date, category_first_id, category_id, desc_category_first_id, "
"first_category_rank, current_category_rank, asin_weight_ratio, site_name, "
"first_category_rank, current_category_rank, asin_weight_ratio, site_name,
asin_type,
"
"asin_bought_month, asin_lqs_rating, asin_lqs_rating_detail, asin_lob_info, is_contains_lob_info, "
"asin_bought_month, asin_lqs_rating, asin_lqs_rating_detail, asin_lob_info, is_contains_lob_info, "
"is_package_quantity_abnormal, zr_flow_proportion, matrix_flow_proportion, matrix_ao_val, "
"is_package_quantity_abnormal, zr_flow_proportion, matrix_flow_proportion, matrix_ao_val, "
"product_features, img_info, collapse_asin, follow_sellers_count, asin_describe, fbm_price, describe_len, "
"product_features, img_info, collapse_asin, follow_sellers_count, asin_describe, fbm_price, describe_len, "
...
@@ -579,6 +582,7 @@ CREATE TABLE IF NOT EXISTS `dwt`.`{site_name}_flow_asin_365day`
...
@@ -579,6 +582,7 @@ CREATE TABLE IF NOT EXISTS `dwt`.`{site_name}_flow_asin_365day`
`package_quantity` INT DEFAULT "1",
`package_quantity` INT DEFAULT "1",
`is_movie_label` TINYINT DEFAULT "0",
`is_movie_label` TINYINT DEFAULT "0",
`is_brand_label` TINYINT DEFAULT "0",
`is_brand_label` TINYINT DEFAULT "0",
`is_alarm_brand` INT DEFAULT "0",
`asin_crawl_date` DATETIME,
`asin_crawl_date` DATETIME,
`category_first_id` STRING,
`category_first_id` STRING,
`category_id` STRING,
`category_id` STRING,
...
@@ -587,6 +591,7 @@ CREATE TABLE IF NOT EXISTS `dwt`.`{site_name}_flow_asin_365day`
...
@@ -587,6 +591,7 @@ CREATE TABLE IF NOT EXISTS `dwt`.`{site_name}_flow_asin_365day`
`current_category_rank` INT,
`current_category_rank` INT,
`asin_weight_ratio` DECIMAL(20,4),
`asin_weight_ratio` DECIMAL(20,4),
`site_name` STRING,
`site_name` STRING,
`asin_type` TINYINT,
`asin_bought_month` INT,
`asin_bought_month` INT,
`asin_lqs_rating` DECIMAL(20,1),
`asin_lqs_rating` DECIMAL(20,1),
`asin_lqs_rating_detail` STRING,
`asin_lqs_rating_detail` STRING,
...
@@ -637,9 +642,9 @@ STG_INSERT_COLUMNS = """
...
@@ -637,9 +642,9 @@ STG_INSERT_COLUMNS = """
variation_rise, variation_mom, variation_yoy,
variation_rise, variation_mom, variation_yoy,
bought_month_mom, bought_month_yoy,
bought_month_mom, bought_month_yoy,
size_type, rating_type, site_name_type, weight_type, ao_val_type, rank_type, price_type,
size_type, rating_type, site_name_type, weight_type, ao_val_type, rank_type, price_type,
quantity_variation_type, package_quantity, is_movie_label, is_brand_label,
quantity_variation_type, package_quantity, is_movie_label, is_brand_label,
is_alarm_brand,
asin_crawl_date, category_first_id, category_id, desc_category_first_id,
asin_crawl_date, category_first_id, category_id, desc_category_first_id,
first_category_rank, current_category_rank, asin_weight_ratio, site_name,
first_category_rank, current_category_rank, asin_weight_ratio, site_name,
asin_type,
asin_bought_month, asin_lqs_rating, asin_lqs_rating_detail,
asin_bought_month, asin_lqs_rating, asin_lqs_rating_detail,
asin_lob_info, is_contains_lob_info, is_package_quantity_abnormal,
asin_lob_info, is_contains_lob_info, is_package_quantity_abnormal,
zr_flow_proportion, matrix_flow_proportion, matrix_ao_val,
zr_flow_proportion, matrix_flow_proportion, matrix_ao_val,
...
@@ -823,7 +828,9 @@ def sync_extra_table(spark, site_name, date_info):
...
@@ -823,7 +828,9 @@ def sync_extra_table(spark, site_name, date_info):
def
build_month_insert_overwrite_sql
(
site_name
,
table_name
,
date_info
):
def
build_month_insert_overwrite_sql
(
site_name
,
table_name
,
date_info
):
"""构建 INSERT OVERWRITE 到 selection.{table_name} 的 SQL;
"""构建 INSERT OVERWRITE 到 selection.{table_name} 的 SQL;
table_name 由外层拼接:{site}_flow_asin_month_{yyyy_mm}[_test]"""
table_name 由外层拼接:{site}_flow_asin_month_{yyyy_mm}[_test]
launch_time_type / tracking_since_type 的天数基准统一用 date_info 当月最后一天"""
type_anchor_date
=
f
"LAST_DAY(CAST(CONCAT('{date_info}', '-01') AS DATE))"
return
f
"""
return
f
"""
INSERT OVERWRITE TABLE `selection`.`{table_name}`
INSERT OVERWRITE TABLE `selection`.`{table_name}`
SELECT
SELECT
...
@@ -871,12 +878,12 @@ SELECT
...
@@ -871,12 +878,12 @@ SELECT
COALESCE(f.launch_time, kp.keepa_launch_time) AS launch_time,
COALESCE(f.launch_time, kp.keepa_launch_time) AS launch_time,
CASE
CASE
WHEN COALESCE(f.launch_time, kp.keepa_launch_time) IS NULL THEN 0
WHEN COALESCE(f.launch_time, kp.keepa_launch_time) IS NULL THEN 0
WHEN DATEDIFF(
f.asin_crawl_date
, COALESCE(f.launch_time, kp.keepa_launch_time)) <= 30 THEN 1
WHEN DATEDIFF(
{type_anchor_date}
, COALESCE(f.launch_time, kp.keepa_launch_time)) <= 30 THEN 1
WHEN DATEDIFF(
f.asin_crawl_date
, COALESCE(f.launch_time, kp.keepa_launch_time)) <= 90 THEN 2
WHEN DATEDIFF(
{type_anchor_date}
, COALESCE(f.launch_time, kp.keepa_launch_time)) <= 90 THEN 2
WHEN DATEDIFF(
f.asin_crawl_date
, COALESCE(f.launch_time, kp.keepa_launch_time)) <= 180 THEN 3
WHEN DATEDIFF(
{type_anchor_date}
, COALESCE(f.launch_time, kp.keepa_launch_time)) <= 180 THEN 3
WHEN DATEDIFF(
f.asin_crawl_date
, COALESCE(f.launch_time, kp.keepa_launch_time)) <= 360 THEN 4
WHEN DATEDIFF(
{type_anchor_date}
, COALESCE(f.launch_time, kp.keepa_launch_time)) <= 360 THEN 4
WHEN DATEDIFF(
f.asin_crawl_date
, COALESCE(f.launch_time, kp.keepa_launch_time)) <= 720 THEN 5
WHEN DATEDIFF(
{type_anchor_date}
, COALESCE(f.launch_time, kp.keepa_launch_time)) <= 720 THEN 5
WHEN DATEDIFF(
f.asin_crawl_date
, COALESCE(f.launch_time, kp.keepa_launch_time)) <= 1080 THEN 6
WHEN DATEDIFF(
{type_anchor_date}
, COALESCE(f.launch_time, kp.keepa_launch_time)) <= 1080 THEN 6
ELSE 7
ELSE 7
END AS launch_time_type,
END AS launch_time_type,
f.img_url,
f.img_url,
...
@@ -912,37 +919,26 @@ SELECT
...
@@ -912,37 +919,26 @@ SELECT
FROM_UNIXTIME((CAST(kp.tracking_since AS BIGINT) + 21564000) * 60) AS tracking_since,
FROM_UNIXTIME((CAST(kp.tracking_since AS BIGINT) + 21564000) * 60) AS tracking_since,
CASE
CASE
WHEN kp.tracking_since IS NULL OR kp.tracking_since <= 0 THEN 0
WHEN kp.tracking_since IS NULL OR kp.tracking_since <= 0 THEN 0
WHEN DATEDIFF(
f.asin_crawl_date
, FROM_UNIXTIME((CAST(kp.tracking_since AS BIGINT) + 21564000) * 60)) <= 30 THEN 1
WHEN DATEDIFF(
{type_anchor_date}
, FROM_UNIXTIME((CAST(kp.tracking_since AS BIGINT) + 21564000) * 60)) <= 30 THEN 1
WHEN DATEDIFF(
f.asin_crawl_date
, FROM_UNIXTIME((CAST(kp.tracking_since AS BIGINT) + 21564000) * 60)) <= 90 THEN 2
WHEN DATEDIFF(
{type_anchor_date}
, FROM_UNIXTIME((CAST(kp.tracking_since AS BIGINT) + 21564000) * 60)) <= 90 THEN 2
WHEN DATEDIFF(
f.asin_crawl_date
, FROM_UNIXTIME((CAST(kp.tracking_since AS BIGINT) + 21564000) * 60)) <= 180 THEN 3
WHEN DATEDIFF(
{type_anchor_date}
, FROM_UNIXTIME((CAST(kp.tracking_since AS BIGINT) + 21564000) * 60)) <= 180 THEN 3
WHEN DATEDIFF(
f.asin_crawl_date
, FROM_UNIXTIME((CAST(kp.tracking_since AS BIGINT) + 21564000) * 60)) <= 360 THEN 4
WHEN DATEDIFF(
{type_anchor_date}
, FROM_UNIXTIME((CAST(kp.tracking_since AS BIGINT) + 21564000) * 60)) <= 360 THEN 4
WHEN DATEDIFF(
f.asin_crawl_date
, FROM_UNIXTIME((CAST(kp.tracking_since AS BIGINT) + 21564000) * 60)) <= 720 THEN 5
WHEN DATEDIFF(
{type_anchor_date}
, FROM_UNIXTIME((CAST(kp.tracking_since AS BIGINT) + 21564000) * 60)) <= 720 THEN 5
WHEN DATEDIFF(
f.asin_crawl_date
, FROM_UNIXTIME((CAST(kp.tracking_since AS BIGINT) + 21564000) * 60)) <= 1080 THEN 6
WHEN DATEDIFF(
{type_anchor_date}
, FROM_UNIXTIME((CAST(kp.tracking_since AS BIGINT) + 21564000) * 60)) <= 1080 THEN 6
ELSE 7
ELSE 7
END AS tracking_since_type,
END AS tracking_since_type,
kp.package_length,
kp.package_length,
kp.package_width,
kp.package_width,
kp.package_height,
kp.package_height,
CASE WHEN kp.item_weight > 0 THEN kp.item_weight ELSE kp.package_weight END AS item_weight,
CASE WHEN kp.item_weight > 0 THEN kp.item_weight ELSE kp.package_weight END AS item_weight,
CASE WHEN ba.brand_name_norm IS NOT NULL THEN 1 ELSE 0 END AS
is_alarm_brand,
f.
is_alarm_brand,
CAST(-1 AS SMALLINT) AS bsr_best_orders_type,
CAST(-1 AS SMALLINT) AS bsr_best_orders_type,
COALESCE(cf.asin_cate_flag, ARRAY(0)) AS asin_source_flag,
COALESCE(cf.asin_cate_flag, ARRAY(0)) AS asin_source_flag,
COALESCE(cf.bsr_latest_date, CAST('1970-01-01' AS DATE)) AS bsr_last_seen_at,
COALESCE(cf.bsr_latest_date, CAST('1970-01-01' AS DATE)) AS bsr_last_seen_at,
COALESCE(cf.bsr_30day_count, 0) AS bsr_seen_count_30d,
COALESCE(cf.bsr_30day_count, 0) AS bsr_seen_count_30d,
COALESCE(cf.nsr_latest_date, CAST('1970-01-01' AS DATE)) AS nsr_last_seen_at,
COALESCE(cf.nsr_latest_date, CAST('1970-01-01' AS DATE)) AS nsr_last_seen_at,
COALESCE(cf.nsr_30day_count, 0) AS nsr_seen_count_30d,
COALESCE(cf.nsr_30day_count, 0) AS nsr_seen_count_30d,
CAST(
f.asin_type,
CASE
WHEN sa.asin IS NOT NULL OR ab.brand_lower IS NOT NULL THEN 1
WHEN (
(COALESCE(chf.is_need_cat, 0) = 1 AND COALESCE(chd.is_need_cat, 0) = 1)
OR f.asin NOT LIKE 'B0
%
'
) THEN 2
WHEN (COALESCE(chf.is_hide_cat, 0) = 1 OR COALESCE(chc.is_hide_cat, 0) = 1)
AND NOT (COALESCE(chf.is_white_cat, 0) = 1 OR COALESCE(chc.is_white_cat, 0) = 1) THEN 3
ELSE 0
END
AS SMALLINT) AS asin_type,
uma.usr_mask_progress,
uma.usr_mask_progress,
COALESCE(uma.usr_mask_type, umc.usr_mask_type) AS usr_mask_type,
COALESCE(uma.usr_mask_type, umc.usr_mask_type) AS usr_mask_type,
COALESCE(aa.auctions_num, 0) AS auctions_num,
COALESCE(aa.auctions_num, 0) AS auctions_num,
...
@@ -959,39 +955,6 @@ LEFT JOIN `dwd`.`dwd_asin_profit_rate_latest` pr
...
@@ -959,39 +955,6 @@ LEFT JOIN `dwd`.`dwd_asin_profit_rate_latest` pr
ON f.asin = pr.asin AND f.price = pr.price AND pr.site_name = '{site_name}'
ON f.asin = pr.asin AND f.price = pr.price AND pr.site_name = '{site_name}'
LEFT JOIN `dwd`.`dwd_keepa_asin_detail` kp
LEFT JOIN `dwd`.`dwd_keepa_asin_detail` kp
ON f.asin = kp.asin AND kp.site_name = '{site_name}'
ON f.asin = kp.asin AND kp.site_name = '{site_name}'
LEFT JOIN (
SELECT DISTINCT LOWER(TRIM(brand_name)) AS brand_name_norm
FROM `selection`.`brand_alert_erp`
WHERE brand_name IS NOT NULL
) ba ON f.brand = ba.brand_name_norm
LEFT JOIN (
SELECT asin FROM `mysql_selection`.`selection`.`us_self_asin` GROUP BY asin
) sa ON f.asin = sa.asin
LEFT JOIN (
SELECT DISTINCT LOWER(TRIM(brand_name)) AS brand_lower
FROM `mysql_selection`.`selection`.`amazon_brand` WHERE brand_type = '1'
) ab ON LOWER(f.brand) = ab.brand_lower
LEFT JOIN (
SELECT category_id_base,
MAX(CASE WHEN hide_type = 'is_need' THEN 1 ELSE 0 END) AS is_need_cat,
MAX(CASE WHEN hide_type = 'is_hide' THEN 1 ELSE 0 END) AS is_hide_cat,
MAX(CASE WHEN hide_type = 'is_white' THEN 1 ELSE 0 END) AS is_white_cat
FROM `mysql_selection`.`selection`.`us_bs_category_hide` GROUP BY category_id_base
) chf ON f.category_first_id = chf.category_id_base
LEFT JOIN (
SELECT category_id_base,
MAX(CASE WHEN hide_type = 'is_need' THEN 1 ELSE 0 END) AS is_need_cat,
MAX(CASE WHEN hide_type = 'is_hide' THEN 1 ELSE 0 END) AS is_hide_cat,
MAX(CASE WHEN hide_type = 'is_white' THEN 1 ELSE 0 END) AS is_white_cat
FROM `mysql_selection`.`selection`.`us_bs_category_hide` GROUP BY category_id_base
) chc ON f.category_id = chc.category_id_base
LEFT JOIN (
SELECT category_id_base,
MAX(CASE WHEN hide_type = 'is_need' THEN 1 ELSE 0 END) AS is_need_cat,
MAX(CASE WHEN hide_type = 'is_hide' THEN 1 ELSE 0 END) AS is_hide_cat,
MAX(CASE WHEN hide_type = 'is_white' THEN 1 ELSE 0 END) AS is_white_cat
FROM `mysql_selection`.`selection`.`us_bs_category_hide` GROUP BY category_id_base
) chd ON f.desc_category_first_id = chd.category_id_base
LEFT JOIN `selection`.`user_mask_asin` uma ON f.asin = uma.asin
LEFT JOIN `selection`.`user_mask_asin` uma ON f.asin = uma.asin
LEFT JOIN `selection`.`user_mask_category` umc ON f.category_id = umc.category_id
LEFT JOIN `selection`.`user_mask_category` umc ON f.category_id = umc.category_id
LEFT JOIN (
LEFT JOIN (
...
@@ -1205,14 +1168,14 @@ def _year_select_from_join_sql(site_name, latest_date_info):
...
@@ -1205,14 +1168,14 @@ def _year_select_from_join_sql(site_name, latest_date_info):
- 主体: dwt.{site}_flow_asin_365day (每 asin 最新月快照,字段名沿用 dwt 月表)
- 主体: dwt.{site}_flow_asin_365day (每 asin 最新月快照,字段名沿用 dwt 月表)
- 年度聚合: dwt.{site}_flow_asin_365day_extra (Hive 算好经 sync_extra_table 同步来的年度指标,
- 年度聚合: dwt.{site}_flow_asin_365day_extra (Hive 算好经 sync_extra_table 同步来的年度指标,
含周期性/季节性/峰值)
含周期性/季节性/峰值)
- 外层 LEFT JOIN: profit_rate / keepa /
brand_alert / self_asin / category_hide /
user_mask / auction 等
- 外层 LEFT JOIN: profit_rate / keepa / user_mask / auction 等
- launch_time_type / tracking_since_type 的天数基准统一用 latest_date_info(本次跑批最新月份)
- launch_time_type / tracking_since_type 的天数基准统一用 latest_date_info(本次跑批最新月份)
的次月初,而不是各批次自身的 f.asin_crawl_date:dwt.{site}_flow_asin_365day 是按 asin 去重只保留
当月的最后一天,而不是各批次自身的 f.asin_crawl_date:dwt.{site}_flow_asin_365day 是按 asin 去重
最新一次快照的表,长期未被重新抓取的 asin 的 asin_crawl_date 会停留在很久之前,用它做基准会导致
只保留最新一次快照的表,长期未被重新抓取的 asin 的 asin_crawl_date 会停留在很久之前,用它做基准
这两个分档字段冻结在过去、不随时间推进
会导致
这两个分档字段冻结在过去、不随时间推进
:param latest_date_info: main() 的 date_info 参数(yyyy-MM),与分批用的历史 date_info_batch 无关
:param latest_date_info: main() 的 date_info 参数(yyyy-MM),与分批用的历史 date_info_batch 无关
"""
"""
type_anchor_date
=
f
"
DATE_ADD(CAST(CONCAT('{latest_date_info}', '-01') AS DATE), INTERVAL 1 MONTH
)"
type_anchor_date
=
f
"
LAST_DAY(CAST(CONCAT('{latest_date_info}', '-01') AS DATE)
)"
return
f
"""
return
f
"""
SELECT
SELECT
f.asin,
f.asin,
...
@@ -1312,20 +1275,9 @@ SELECT
...
@@ -1312,20 +1275,9 @@ SELECT
kp.package_width,
kp.package_width,
kp.package_height,
kp.package_height,
CASE WHEN kp.item_weight > 0 THEN kp.item_weight ELSE kp.package_weight END AS item_weight,
CASE WHEN kp.item_weight > 0 THEN kp.item_weight ELSE kp.package_weight END AS item_weight,
CASE WHEN ba.brand_name_norm IS NOT NULL THEN 1 ELSE 0 END AS
is_alarm_brand,
f.
is_alarm_brand,
CAST(-1 AS SMALLINT) AS bsr_best_orders_type,
CAST(-1 AS SMALLINT) AS bsr_best_orders_type,
CAST(
f.asin_type,
CASE
WHEN sa.asin IS NOT NULL OR ab.brand_lower IS NOT NULL THEN 1
WHEN (
(COALESCE(chf.is_need_cat, 0) = 1 AND COALESCE(chd.is_need_cat, 0) = 1)
OR f.asin NOT LIKE 'B0
%
'
) THEN 2
WHEN (COALESCE(chf.is_hide_cat, 0) = 1 OR COALESCE(chc.is_hide_cat, 0) = 1)
AND NOT (COALESCE(chf.is_white_cat, 0) = 1 OR COALESCE(chc.is_white_cat, 0) = 1) THEN 3
ELSE 0
END
AS SMALLINT) AS asin_type,
uma.usr_mask_progress,
uma.usr_mask_progress,
COALESCE(uma.usr_mask_type, umc.usr_mask_type) AS usr_mask_type,
COALESCE(uma.usr_mask_type, umc.usr_mask_type) AS usr_mask_type,
COALESCE(aa.auctions_num, 0) AS auctions_num,
COALESCE(aa.auctions_num, 0) AS auctions_num,
...
@@ -1359,45 +1311,6 @@ LEFT JOIN `dwd`.`dwd_asin_profit_rate_latest` pr
...
@@ -1359,45 +1311,6 @@ LEFT JOIN `dwd`.`dwd_asin_profit_rate_latest` pr
-- ===== Keepa 详情 =====
-- ===== Keepa 详情 =====
LEFT JOIN `dwd`.`dwd_keepa_asin_detail` kp
LEFT JOIN `dwd`.`dwd_keepa_asin_detail` kp
ON f.asin = kp.asin AND kp.site_name = '{site_name}'
ON f.asin = kp.asin AND kp.site_name = '{site_name}'
-- ===== 预警品牌 =====
LEFT JOIN (
SELECT DISTINCT LOWER(TRIM(brand_name)) AS brand_name_norm
FROM `selection`.`brand_alert_erp`
WHERE brand_name IS NOT NULL
) ba ON f.brand = ba.brand_name_norm
-- ===== 自营 ASIN =====
LEFT JOIN (
SELECT asin FROM `mysql_selection`.`selection`.`us_self_asin` GROUP BY asin
) sa ON f.asin = sa.asin
-- ===== 自有品牌 =====
LEFT JOIN (
SELECT DISTINCT LOWER(TRIM(brand_name)) AS brand_lower
FROM `mysql_selection`.`selection`.`amazon_brand` WHERE brand_type = '1'
) ab ON LOWER(f.brand) = ab.brand_lower
-- ===== 一级分类规则 =====
LEFT JOIN (
SELECT category_id_base,
MAX(CASE WHEN hide_type = 'is_need' THEN 1 ELSE 0 END) AS is_need_cat,
MAX(CASE WHEN hide_type = 'is_hide' THEN 1 ELSE 0 END) AS is_hide_cat,
MAX(CASE WHEN hide_type = 'is_white' THEN 1 ELSE 0 END) AS is_white_cat
FROM `mysql_selection`.`selection`.`us_bs_category_hide` GROUP BY category_id_base
) chf ON f.category_first_id = chf.category_id_base
-- ===== 当前分类规则 =====
LEFT JOIN (
SELECT category_id_base,
MAX(CASE WHEN hide_type = 'is_need' THEN 1 ELSE 0 END) AS is_need_cat,
MAX(CASE WHEN hide_type = 'is_hide' THEN 1 ELSE 0 END) AS is_hide_cat,
MAX(CASE WHEN hide_type = 'is_white' THEN 1 ELSE 0 END) AS is_white_cat
FROM `mysql_selection`.`selection`.`us_bs_category_hide` GROUP BY category_id_base
) chc ON f.category_id = chc.category_id_base
-- ===== 描述匹配分类规则 =====
LEFT JOIN (
SELECT category_id_base,
MAX(CASE WHEN hide_type = 'is_need' THEN 1 ELSE 0 END) AS is_need_cat,
MAX(CASE WHEN hide_type = 'is_hide' THEN 1 ELSE 0 END) AS is_hide_cat,
MAX(CASE WHEN hide_type = 'is_white' THEN 1 ELSE 0 END) AS is_white_cat
FROM `mysql_selection`.`selection`.`us_bs_category_hide` GROUP BY category_id_base
) chd ON f.desc_category_first_id = chd.category_id_base
-- ===== 用户标记 ASIN/品类 =====
-- ===== 用户标记 ASIN/品类 =====
LEFT JOIN `selection`.`user_mask_asin` uma ON f.asin = uma.asin
LEFT JOIN `selection`.`user_mask_asin` uma ON f.asin = uma.asin
LEFT JOIN `selection`.`user_mask_category` umc ON f.category_id = umc.category_id
LEFT JOIN `selection`.`user_mask_category` umc ON f.category_id = umc.category_id
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment