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
f876e6ea
Commit
f876e6ea
authored
Aug 07, 2026
by
chenyuanjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bsr分类模块-兼容landing_asin判断asin跳转
parent
91bd0f0a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
8 deletions
+8
-8
dwt_bs_top100.py
Pyspark_job/dwt/dwt_bs_top100.py
+8
-8
No files found.
Pyspark_job/dwt/dwt_bs_top100.py
View file @
f876e6ea
...
@@ -141,16 +141,16 @@ class DwtBsTop100(Templates):
...
@@ -141,16 +141,16 @@ class DwtBsTop100(Templates):
# 【取 node_id:重定向感知映射,不改 dwt_flow】
# 【取 node_id:重定向感知映射,不改 dwt_flow】
# 为什么不直接用 dwt_flow 里的 node:dwt_flow 不带 node 列;若拿 dwt_flow 的 asin 回 join
# 为什么不直接用 dwt_flow 里的 node:dwt_flow 不带 node 列;若拿 dwt_flow 的 asin 回 join
# dim_asin_detail 会踩重定向坑——dwt_flow_asin.py 的 handle_asin_redirect 把 asin 换成了
# dim_asin_detail 会踩重定向坑——dwt_flow_asin.py 的 handle_asin_redirect 把 asin 换成了
#
current
_asin(跳转目标),而 dim_asin_detail 存的是原始 asin,直接 join 会大面积假"缺 node"。
#
landing
_asin(跳转目标),而 dim_asin_detail 存的是原始 asin,直接 join 会大面积假"缺 node"。
# 做法:读 dim 四小列,复刻 dwt_flow 的重定向变换:key=coalesce(
current
_asin, asin),
# 做法:读 dim 四小列,复刻 dwt_flow 的重定向变换:key=coalesce(
landing
_asin, asin),
# 同 key 按 created_time 降序留一条,得到"重定向后 asin → node_id",键就能和 dwt_flow 的 asin 对上。
# 同 key 按 created_time 降序留一条,得到"重定向后 asin → node_id",键就能和 dwt_flow 的 asin 对上。
# ============================================================
# ============================================================
sql_node
=
f
"""select asin,
current
_asin, node_id, created_time
sql_node
=
f
"""select asin,
landing
_asin, node_id, created_time
from dim_asin_detail
from dim_asin_detail
where site_name='{self.site_name}' and date_type='{self.date_type}' and date_info='{self.date_info}'"""
where site_name='{self.site_name}' and date_type='{self.date_type}' and date_info='{self.date_info}'"""
print
(
f
"3. 读取 dim_asin_detail 取 node_id: sql -- {sql_node}"
)
print
(
f
"3. 读取 dim_asin_detail 取 node_id: sql -- {sql_node}"
)
df_node
=
self
.
spark
.
sql
(
sql_node
)
df_node
=
self
.
spark
.
sql
(
sql_node
)
df_node
=
df_node
.
withColumn
(
"asin_eff"
,
F
.
coalesce
(
F
.
col
(
"
current
_asin"
),
F
.
col
(
"asin"
)))
df_node
=
df_node
.
withColumn
(
"asin_eff"
,
F
.
coalesce
(
F
.
col
(
"
landing
_asin"
),
F
.
col
(
"asin"
)))
w_node
=
Window
.
partitionBy
(
"asin_eff"
)
.
orderBy
(
F
.
col
(
"created_time"
)
.
desc_nulls_last
())
w_node
=
Window
.
partitionBy
(
"asin_eff"
)
.
orderBy
(
F
.
col
(
"created_time"
)
.
desc_nulls_last
())
df_node
=
df_node
.
withColumn
(
"_rk"
,
F
.
row_number
()
.
over
(
w_node
))
.
filter
(
F
.
col
(
"_rk"
)
==
1
)
df_node
=
df_node
.
withColumn
(
"_rk"
,
F
.
row_number
()
.
over
(
w_node
))
.
filter
(
F
.
col
(
"_rk"
)
==
1
)
# 输出成 asin(重定向后)→ node_id,node_id 转 string 与 keepa cat_id 对齐
# 输出成 asin(重定向后)→ node_id,node_id 转 string 与 keepa cat_id 对齐
...
@@ -179,7 +179,7 @@ class DwtBsTop100(Templates):
...
@@ -179,7 +179,7 @@ class DwtBsTop100(Templates):
并复刻 dwt_flow 的跳转(coalesce+created_time 最新去重)对齐到重定向 asin,和 df_bs_data 同 grain。
并复刻 dwt_flow 的跳转(coalesce+created_time 最新去重)对齐到重定向 asin,和 df_bs_data 同 grain。
"""
"""
# 读 dim 原始 launch 及跳转所需列(与 df_node 同一张 dim,单独取以带上 asin_launch_time)
# 读 dim 原始 launch 及跳转所需列(与 df_node 同一张 dim,单独取以带上 asin_launch_time)
sql_dim
=
f
"""select asin,
current
_asin, asin_launch_time, created_time
sql_dim
=
f
"""select asin,
landing
_asin, asin_launch_time, created_time
from dim_asin_detail
from dim_asin_detail
where site_name='{self.site_name}' and date_type='{self.date_type}' and date_info='{self.date_info}'"""
where site_name='{self.site_name}' and date_type='{self.date_type}' and date_info='{self.date_info}'"""
print
(
f
"读取 dim_asin_detail 重算新品: sql -- {sql_dim}"
)
print
(
f
"读取 dim_asin_detail 重算新品: sql -- {sql_dim}"
)
...
@@ -202,8 +202,8 @@ class DwtBsTop100(Templates):
...
@@ -202,8 +202,8 @@ class DwtBsTop100(Templates):
df_dim
=
df_dim
.
withColumn
(
df_dim
=
df_dim
.
withColumn
(
"asin_is_new_recalc"
,
"asin_is_new_recalc"
,
self
.
udf_new_asin_flag
(
F
.
greatest
(
F
.
col
(
'asin_launch_time'
),
F
.
col
(
'keepa_tracking_since'
)),
F
.
lit
(
cal_date
)))
self
.
udf_new_asin_flag
(
F
.
greatest
(
F
.
col
(
'asin_launch_time'
),
F
.
col
(
'keepa_tracking_since'
)),
F
.
lit
(
cal_date
)))
# 复刻 dwt_flow 跳转:target=coalesce(
current
_asin,asin),同 target 按 created_time 最新留一条
# 复刻 dwt_flow 跳转:target=coalesce(
landing
_asin,asin),同 target 按 created_time 最新留一条
df_dim
=
df_dim
.
withColumn
(
"asin_eff"
,
F
.
coalesce
(
F
.
col
(
"
current
_asin"
),
F
.
col
(
"asin"
)))
df_dim
=
df_dim
.
withColumn
(
"asin_eff"
,
F
.
coalesce
(
F
.
col
(
"
landing
_asin"
),
F
.
col
(
"asin"
)))
w
=
Window
.
partitionBy
(
"asin_eff"
)
.
orderBy
(
F
.
col
(
"created_time"
)
.
desc_nulls_last
())
w
=
Window
.
partitionBy
(
"asin_eff"
)
.
orderBy
(
F
.
col
(
"created_time"
)
.
desc_nulls_last
())
df_dim
=
df_dim
.
withColumn
(
"_rk"
,
F
.
row_number
()
.
over
(
w
))
.
filter
(
F
.
col
(
"_rk"
)
==
1
)
df_dim
=
df_dim
.
withColumn
(
"_rk"
,
F
.
row_number
()
.
over
(
w
))
.
filter
(
F
.
col
(
"_rk"
)
==
1
)
return
df_dim
.
select
(
F
.
col
(
"asin_eff"
)
.
alias
(
"asin"
),
F
.
col
(
"asin_is_new_recalc"
))
return
df_dim
.
select
(
F
.
col
(
"asin_eff"
)
.
alias
(
"asin"
),
F
.
col
(
"asin_is_new_recalc"
))
...
@@ -412,7 +412,7 @@ class DwtBsTop100(Templates):
...
@@ -412,7 +412,7 @@ class DwtBsTop100(Templates):
print
(
"handle_bs_node_attach 调用(node_id 归属)"
)
print
(
"handle_bs_node_attach 调用(node_id 归属)"
)
# ============================================================
# ============================================================
# Step 1:给 asin 挂 node_id
# Step 1:给 asin 挂 node_id
# 【为什么 join on asin】df_node 的 key 已按 coalesce(
current
_asin, asin) 复刻了 dwt_flow 的重定向,
# 【为什么 join on asin】df_node 的 key 已按 coalesce(
landing
_asin, asin) 复刻了 dwt_flow 的重定向,
# 而 df_bs_data 的 asin 也是 dwt_flow 重定向后的 asin,两边键对得上。
# 而 df_bs_data 的 asin 也是 dwt_flow 重定向后的 asin,两边键对得上。
# 【dwt_flow 是 asin 粒度】一个 asin 一行,join 后仍一个 asin 一行(df_node 也已按 asin 去重)。
# 【dwt_flow 是 asin 粒度】一个 asin 一行,join 后仍一个 asin 一行(df_node 也已按 asin 去重)。
# ============================================================
# ============================================================
...
...
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