SuperAPI AI 工具集

02-merge-patterns

通用与其它

查看项目

更新于 10-15 20:32

技能介绍

用途:为 Gold 层从 Silver 表构建 MERGE 操作提供生产级模式与模板,强调 schema 感知的转换。

主要能力:覆盖列名映射(用 withColumn 显式重命名,如 company_rcn 映射为 company_retail_control_number)、数据类型转换、业务计算、SCD Type 1(覆盖更新,whenMatchedUpdateAll/whenNotMatchedInsertAll)、SCD Type 2(历史追踪,含 effective_from/effective_to/is_current,仅更新当前记录时间戳)、事实表按日聚合。另有高级模式:累积快照、无事实事实表、周期快照、junk 维度(按 YAML 的 grain_type 与 dimension_pattern 选择模板)。

必要用法与限制:合并前必须先用 03-deduplication 去重;先合并维度再合并事实;列映射来自 YAML lineage 与 COLUMN_LINEAGE.csv,不要硬编码重命名;避免变量名遮蔽 PySpark 函数(如用 record_count 而非 count,sum 用 spark_sum 别名);SCD Type 2 必须包含 is_current 过滤;显式 cast 匹配目标 schema;用 try/except 处理错误。适合零售等零售销售、库存快照、门店/产品维度建模场景。

模板文件位于 assets/templates/ 下的 scd-type1-merge.py、scd-type2-merge.py、fact-table-aggregation-merge.py、accumulating-snapshot-merge.py、factless-fact-merge.py、periodic-snapshot-merge.py、junk-dimension-populate.py。具体收费、价格、平台效果资料暂未提供。