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
599cd475
Commit
599cd475
authored
Sep 02, 2026
by
hejiangming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增卖家类型占比合并字段
parent
261ec1a7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
3 deletions
+23
-3
dwt_bs_top100.py
Pyspark_job/dwt/dwt_bs_top100.py
+18
-2
dwt_bs_top100.py
Pyspark_job/sqoop_export/dwt_bs_top100.py
+5
-1
No files found.
Pyspark_job/dwt/dwt_bs_top100.py
View file @
599cd475
...
...
@@ -334,6 +334,13 @@ class DwtBsTop100(Templates):
for
rate
in
range
(
5
):
self
.
df_bs_data
=
self
.
df_bs_data
.
withColumn
(
f
"asin_buy_box_seller_type{rate}_rate"
,
self
.
df_bs_data
[
"asin_buy_box_seller_type"
]
==
rate
)
# 页面只展示 4 档(Amazon/FBA/FBM/其他),type0(爬虫没抓到卖家信息)并进"其他",原 type0~type4 五列保留不动。
# 2024-05 起 dim_asin_detail 走 udf_parse_seller_json,seller_json 空/无 seller_id/解析失败都返回 0,
# 所以本表跑到的月份 seller_type 无 null,这里等价于 isin(0,4);
# 写成"非 1/2/3 即其他"是为了 2024-05 前的老分区(那时用源表原值、可为 null)也能四档互斥穷尽、相加恒=1。
self
.
df_bs_data
=
self
.
df_bs_data
.
withColumn
(
"asin_buy_box_seller_type_other_rate"
,
F
.
when
(
F
.
col
(
"asin_buy_box_seller_type"
)
.
isin
(
1
,
2
,
3
),
False
)
.
otherwise
(
True
))
# ============================================================
# 【卖家所属地占比】 造 3 个布尔列(美/中/其他),走 rate 路径——handle_bs_level 里 rate_cols
...
...
@@ -627,6 +634,8 @@ class DwtBsTop100(Templates):
'asin_buy_box_seller_type0_rate'
,
'asin_buy_box_seller_type1_rate'
,
'asin_buy_box_seller_type2_rate'
,
'asin_buy_box_seller_type3_rate'
,
'asin_buy_box_seller_type4_rate'
,
# 卖家类型"其他"档(type0+type4+null 合并),带进拆行 select 才能活到 rate 路径求占比
'asin_buy_box_seller_type_other_rate'
,
'seller_country_us_rate'
,
'seller_country_cn_rate'
,
'seller_country_other_rate'
,
'asin_orders_ge_50_rate'
,
'asin_orders_ge_100_rate'
,
'asin_orders_ge_200_rate'
,
'asin_brand_name'
,
'account_id'
,
...
...
@@ -1220,6 +1229,8 @@ class DwtBsTop100(Templates):
"asin_buy_box_seller_type0_rate"
,
"asin_buy_box_seller_type1_rate"
,
"asin_buy_box_seller_type2_rate"
,
"asin_buy_box_seller_type3_rate"
,
"asin_buy_box_seller_type4_rate"
,
# "其他"档(=type0+type4):与上面五列同为数量占比,同样 ÷ asin_count。与 type1/2/3 互斥穷尽、四者相加=1。
"asin_buy_box_seller_type_other_rate"
,
# 卖家所属地 3 列:与上架时间/卖家类型同为"数量占比",同样 ÷ asin_count。
# 三列 null-safe 互斥穷尽(见 handle_bs_categorical_data),计数和=asin_count → 三占比相加=1。
"seller_country_us_rate"
,
"seller_country_cn_rate"
,
"seller_country_other_rate"
,
...
...
@@ -1259,7 +1270,8 @@ class DwtBsTop100(Templates):
# ============================================================
# 44 业务列 + 利润率均值2 + 区间利润率24(self.band_margin_cols)
# + 打包占比7 + 卖家地占比3 + 月销阈值占比3 + 集中度3 = 86 列,再 + 3 分区列。
# + 打包占比7 + 卖家地占比3 + 月销阈值占比3 + 集中度3 + 卖家类型其他档1 = 88 列,再 + 3 分区列。
# (原注释写 44 业务列/86 列,实际 business_cols 是 45 个,已按脚本核对修正)
# ============================================================
business_cols
=
[
"asin_node_current_id"
,
...
...
@@ -1282,8 +1294,12 @@ class DwtBsTop100(Templates):
country_cols
=
[
"seller_country_us_rate"
,
"seller_country_cn_rate"
,
"seller_country_other_rate"
]
orders_ge_cols
=
[
"asin_orders_ge_50_rate"
,
"asin_orders_ge_100_rate"
,
"asin_orders_ge_200_rate"
]
conc_cols
=
[
"asin_concentration"
,
"brand_concentration"
,
"seller_concentration"
]
# 卖家类型"其他"档:放最末尾,与 Hive 表列顺序对齐。
# saveAsTable 本身按列名映射、df 顺序无所谓;但这张表是 LazySimpleSerDe 文本格式,
# 表定义的列顺序=数据文件里字段的物理顺序,新列插中间会让只有 86 字段的老分区整体错位。
seller_type_other_cols
=
[
"asin_buy_box_seller_type_other_rate"
]
final_cols
=
business_cols
+
profit_avg_cols
+
list
(
self
.
band_margin_cols
)
\
+
pkg_rate_cols
+
country_cols
+
orders_ge_cols
+
conc_cols
+
pkg_rate_cols
+
country_cols
+
orders_ge_cols
+
conc_cols
+
seller_type_other_cols
# ============================================================
# 【销量/金额 sum 列】某分类全无月销时 sum=null → coalesce(0)(0=无销量,有意义,区别于利润率的"无数据")。
...
...
Pyspark_job/sqoop_export/dwt_bs_top100.py
View file @
599cd475
...
...
@@ -79,7 +79,8 @@ if __name__ == '__main__':
"""
DBUtil
.
engine_exec_sql
(
engine
,
sql
)
# 导出列 = 86 业务列 + 3 分区列(列名与 Hive dwt_bs_top100 一致, sqoop 按名映射 PG 同名列)
# 导出列 = 88 业务列 + 3 分区列(列名与 Hive dwt_bs_top100 一致, 走 hcatalog 按字段名映射 PG 同名列,
# 故这里的顺序不必与 Hive 表列序一致;PG 表必须有同名列,否则 sqoop 报列不存在)
export_cols
=
[
# 维度 / 键
"asin_node_current_id"
,
"asin_node_parent_id"
,
"asin_node_parent_id_join"
,
...
...
@@ -100,8 +101,11 @@ if __name__ == '__main__':
"launch_time_type0_rate"
,
"launch_time_type1_rate"
,
"launch_time_type2_rate"
,
"launch_time_type3_rate"
,
"launch_time_type4_rate"
,
"launch_time_type5_rate"
,
"launch_time_type6_rate"
,
"launch_time_type7_rate"
,
# 卖家类型分布
# type0(爬虫没抓到卖家信息)/type4(归不了 Amazon/FBA/FBM) 页面不单独展示,合并成 other 一档,
# 页面用 type1/2/3 + other 四档,四者相加=1。两个老列仍导出、保留备查。
"asin_buy_box_seller_type0_rate"
,
"asin_buy_box_seller_type1_rate"
,
"asin_buy_box_seller_type2_rate"
,
"asin_buy_box_seller_type3_rate"
,
"asin_buy_box_seller_type4_rate"
,
"asin_buy_box_seller_type_other_rate"
,
# 卖家所属地占比
"seller_country_us_rate"
,
"seller_country_cn_rate"
,
"seller_country_other_rate"
,
# 月销阈值占比
...
...
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