@dazitech/cli 3.0.8 → 3.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/README.md +1 -1
  2. package/dist/clis/dazi-app.js +1 -1
  3. package/dist/clis/dazi-flow.js +1 -1
  4. package/dist/clis/dazi-onto.js +1 -1
  5. package/dist/clis/dazi.js +1 -1
  6. package/dist/docs/flow/flow-project-guide.md +1 -1
  7. package/dist/docs/guides/troubleshooting.md +12 -1
  8. package/dist/docs/index.json +20 -1
  9. package/dist/docs/onto/dazi_script_sdk_reference.md +78 -12
  10. package/dist/docs/onto/function-guide.md +61 -33
  11. package/dist/docs/onto//346/234/254/344/275/223/345/210/206/347/261/273/350/247/204/345/210/222/344/270/216SDK/346/211/251/345/261/225/346/226/271/346/241/210.md +168 -0
  12. package/dist/docs/onto//346/234/254/344/275/223/345/221/275/345/220/215/350/247/204/350/214/203_/347/211/251/347/220/206/350/241/250Cube/344/270/216/345/257/271/350/261/241.md +402 -0
  13. package/dist/docs/onto//346/234/254/344/275/223/350/204/232/346/234/254/347/274/226/345/206/231/346/214/207/345/215/227.md +63 -1
  14. package/dist/docs/onto//346/234/254/344/275/223/350/247/204/345/210/222/346/214/207/345/215/227.md +123 -15
  15. package/dist/docs/onto//350/204/232/346/234/254/350/277/220/350/241/214/347/272/240/351/224/231_/345/225/206/345/212/241/346/210/220/346/234/254/346/226/271/346/241/210/345/274/200/345/217/221/350/277/207/347/250/213.md +213 -0
  16. package/dist/docs/onto//350/247/204/345/210/222/347/244/272/344/276/213_/344/272/247/345/223/201/351/224/200/345/224/256/346/234/254/344/275/223/350/247/204/345/210/222/346/226/271/346/241/210.md +356 -233
  17. package/dist/docs/onto//350/247/204/345/210/222/347/244/272/344/276/213_/345/210/251/346/266/246/345/210/206/346/236/220/346/234/254/344/275/223/346/226/271/346/241/210.md +379 -296
  18. package/dist/examples/index.json +23 -17
  19. package/dist/examples/onto/README.md +13 -5
  20. package/dist/examples/onto/_templates/ontology_function_template.py +50 -0
  21. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_account_breakdown.py +62 -0
  22. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_budget_vs_actual.py +69 -0
  23. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_cost_center_profit.py +64 -0
  24. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_get_summary.py +61 -0
  25. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_mom_analysis.py +82 -0
  26. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_top_accounts.py +61 -0
  27. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_yoy_analysis.py +79 -0
  28. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/save_test_arguments.ps1 +38 -0
  29. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/test_arguments/profit.fn.account_breakdown.json +1 -0
  30. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/test_arguments/profit.fn.budget_vs_actual.json +1 -0
  31. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/test_arguments/profit.fn.cost_center_profit.json +1 -0
  32. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/test_arguments/profit.fn.get_summary.json +1 -0
  33. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/test_arguments/profit.fn.mom_analysis.json +1 -0
  34. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/test_arguments/profit.fn.top_accounts.json +1 -0
  35. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/test_arguments/profit.fn.yoy_analysis.json +1 -0
  36. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_ontology_init.py +232 -74
  37. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_seed_data.py +16 -13
  38. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_channel_mix.py +19 -16
  39. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_customer_segmentation.py +48 -50
  40. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_get_summary.py +3 -6
  41. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_mom_analysis.py +11 -12
  42. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_region_breakdown.py +6 -7
  43. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_top_products.py +5 -8
  44. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_yoy_analysis.py +3 -6
  45. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/save_test_arguments.ps1 +32 -19
  46. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.channel_mix.json +3 -6
  47. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.customer_segmentation.json +2 -7
  48. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.get_summary.json +2 -5
  49. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.mom_analysis.json +2 -5
  50. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.region_breakdown.json +2 -5
  51. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.top_products.json +2 -7
  52. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.yoy_analysis.json +2 -5
  53. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_ontology_init.py +291 -155
  54. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_seed_data.py +59 -20
  55. package/dist/prompts/index.json +1 -1
  56. package/dist/prompts/onto/function-design.md +42 -22
  57. package/dist/prompts/onto/script-publish-run.md +15 -1
  58. package/package.json +1 -1
  59. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_account_breakdown.py +0 -99
  60. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_budget_vs_actual.py +0 -116
  61. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_cost_center_profit.py +0 -85
  62. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_get_summary.py +0 -76
  63. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_mom_analysis.py +0 -86
  64. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_top_accounts.py +0 -103
  65. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_yoy_analysis.py +0 -86
  66. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/save_test_arguments.ps1 +0 -27
  67. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.account_breakdown.json +0 -10
  68. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.budget_vs_actual.json +0 -10
  69. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.cost_center_profit.json +0 -9
  70. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.get_summary.json +0 -9
  71. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.mom_analysis.json +0 -9
  72. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.top_accounts.json +0 -11
  73. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.yoy_analysis.json +0 -9
  74. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/README.md +0 -25
  75. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/README.md +0 -5
@@ -0,0 +1,402 @@
1
+ # 本体命名规范 · 物理表、Cube 与对象
2
+
3
+ **文档 ID**: `onto/naming-conventions`
4
+
5
+ > **类型**:规范(物理层 · Cube 层 · 本体层 · 三层对照)
6
+ > **适用版本**:`dazi-vscode` v3.0.9+
7
+ > **前置阅读**:[本体规划指南](./本体规划指南.md)
8
+
9
+ ---
10
+
11
+ ## 目录
12
+
13
+ 1. [总则:三层各有一套命名语言](#1-总则三层各有一套命名语言)
14
+ 2. [物理表:类别与前缀](#2-物理表类别与前缀)
15
+ 3. [时间维 dim_date(强制)](#3-时间维-dim_date强制)
16
+ 4. [Cube:类别与命名](#4-cube类别与命名)
17
+ 5. [本体对象:Palantir 思想与分类](#5-本体对象palantir-思想与分类)
18
+ 6. [链接类型命名](#6-链接类型命名)
19
+ 7. [三层对照与迁移示例(销售域)](#7-三层对照与迁移示例销售域)
20
+ 8. [规划文档写法与自检清单](#8-规划文档写法与自检清单)
21
+ 9. [相关文档索引](#9-相关文档索引)
22
+
23
+ ---
24
+
25
+ ## 1. 总则:三层各有一套命名语言
26
+
27
+ 本体规划须同时设计 **物理表、Cube、本体对象** 三层;三者 **刻意区分命名**,避免「一张表一个对象一个 Cube 同名」的一一复制。
28
+
29
+ | 层级 | 面向谁 | 命名风格 | 核心原则 |
30
+ | ---- | ------ | -------- | -------- |
31
+ | **物理表** | DBA / ETL / ClickHouse | **`{前缀}_{实体}`** snake_case | 从表名即可判断存储角色(事实/维/桥/配置…) |
32
+ | **Cube** | 分析 / 报表 / 语义层 | **`{主题}{Analytics\|Cube}`** PascalCase | 表达**分析主题与粒度**,可共享同一 fact 表 |
33
+ | **本体对象** | 业务 / 产品 / 智能体 | **`{业务名词}`** PascalCase,**无前缀** | 贴近 **业务世界**(Palantir Object Type 思想),用**分类**而非前缀区分角色 |
34
+
35
+ ```text
36
+ 业务世界(本体) 分析语义(Cube) 存储落地(物理表)
37
+ ───────────────── ───────────────── ─────────────────
38
+ Product ←── ProductSalesCube ←── dim_product
39
+ SalesOrder ←── SalesCube ←── fact_sales_order_line
40
+ (时间分析) ←── (SalesCube 时间维) ←── dim_date + date_key
41
+ ```
42
+
43
+ **规划顺序(推荐)**:
44
+
45
+ 1. 列出 **本体对象类型** 与 **链接**(业务语言)
46
+ 2. 反推需要的 **Cube**(读模型 / 度量白名单)
47
+ 3. 再落 **物理表**(fact / dim / dim_date / bridge…)
48
+
49
+ ---
50
+
51
+ ## 2. 物理表:类别与前缀
52
+
53
+ ### 2.1 命名格式
54
+
55
+ ```text
56
+ {类别前缀}_{业务域}_{实体}[_{粒度}]
57
+ ```
58
+
59
+ - 全小写 **snake_case**
60
+ - **类别前缀必填**;禁止 `product_master`、`customer_dimension` 等混用后缀
61
+ - 单域实现可省略业务域:`dim_product`;多域共空间时用 `dim_sales_product`
62
+
63
+ ### 2.2 表类别(7 类 + 强制时间维)
64
+
65
+ | 前缀 | 角色 | 典型粒度 | 本体读模型 | 规划必写 |
66
+ | ---- | ---- | -------- | ---------- | -------- |
67
+ | **`dim_`** | 维度 / 主数据 | 一行一实体 | 是(或经 JOIN 进 Cube) | 业务维表必写 |
68
+ | **`fact_`** | 事实 / 明细 / 事件 | 一行一业务事件 | **是(Cube 主源)** | 核心必写 |
69
+ | **`bridge_`** | 桥表(多对多) | 关系对 | 视场景 | 有多对多时必写 |
70
+ | **`map_`** | 映射 / 对照 / 码表 | 源→目标 | 辅助 | 有码表转换时写 |
71
+ | **`cfg_`** | 配置 / 参数 / 版本 | 配置行 | 一般不作分析对象 | 有预算版本等时写 |
72
+ | **`agg_`** | 预聚合 / 主题汇总 | 维组合汇总 | 可选(性能层) | 有固定汇总口径时写 |
73
+ | **`tmp_`** | 临时 / 中间 | 不限 | **否** | 仅 ETL 说明,不进核心表清单 |
74
+
75
+ ### 2.3 各类约束摘要
76
+
77
+ **`fact_*`**
78
+
79
+ - 含可加性度量或事件计数
80
+ - **必须**含 **`date_key`** → `dim_date`(见 §3)
81
+ - 可保留业务日期列(如 `order_date`)作展示;**分析 JOIN 优先 `date_key`**
82
+ - 外键与维表 PK **同名**:`product_id`、`customer_id`
83
+
84
+ **`dim_*`**
85
+
86
+ - PK:`{entity}_id`(或与事实表 FK 统一的 `{entity}_key`)
87
+ - 规划注明 SCD 策略(Type 1 / Type 2)
88
+
89
+ **`bridge_*` / `map_*` / `cfg_*` / `agg_*` / `tmp_*`**
90
+
91
+ - 见 §2.2;`tmp_*` 不得作为 `bind_source` 或 Cube 唯一事实源
92
+
93
+ ### 2.4 主键 / 外键约定
94
+
95
+ | 对象 | 约定 | 示例 |
96
+ | ---- | ---- | ---- |
97
+ | 时间维 PK | **`date_key`** Int32 | `20250605`(YYYYMMDD) |
98
+ | 业务维 PK | `{entity}_id` | `product_id` |
99
+ | 事实表 FK | 与维表 PK **同名** | `date_key`, `product_id` |
100
+
101
+ ---
102
+
103
+ ## 3. 时间维 dim_date(强制)
104
+
105
+ ### 3.1 何时必须
106
+
107
+ | 场景 | 要求 |
108
+ | ---- | ---- |
109
+ | 任意含日期的 **`fact_*`** | **必须** `dim_date` + 事实表 **`date_key`** |
110
+ | 仅时点快照、无趋势 | 可豁免,规划 **显式说明理由** |
111
+ | 公历 + 会计期间 | **一张** `dim_date`,用列扩展(`fiscal_year`, `fiscal_period`) |
112
+
113
+ ### 3.2 最小字段集
114
+
115
+ **表名**:`dim_date`(**全空间通常唯一一张**)
116
+
117
+ | 字段 | 类型 | 说明 |
118
+ | ---- | ---- | ---- |
119
+ | **`date_key`** | **Int32** | **PK**,推荐 `YYYYMMDD` |
120
+ | `calendar_date` | Date | 自然日 |
121
+ | `year` / `quarter` / `month` | Int | 公历层次 |
122
+ | `week_of_year` / `day_of_week` | Int | 周、星期 |
123
+ | `is_weekend` | UInt8 | 0/1 |
124
+ | `year_month` | String | 如 `2025-06` |
125
+ | `fiscal_year` / `fiscal_period` | Int | 会计日历(可选) |
126
+
127
+ **排序键**:`ORDER BY (date_key)`
128
+
129
+ ### 3.3 事实表关联
130
+
131
+ ```text
132
+ fact_*.date_key → dim_date.date_key
133
+ ```
134
+
135
+ 灌数:`date_key = toYYYYMMDD(order_date)`。YoY/MoM 函数优先通过 **`dim_date`** 做 period shift,而非硬编码 `toYear(order_date)`。
136
+
137
+ ---
138
+
139
+ ## 4. Cube:类别与命名
140
+
141
+ Cube 是 **物理表 → 分析语义 → 本体读模型** 的中间层;命名应体现 **分析主题**,而非复制表名或对象名。
142
+
143
+ ### 4.1 命名格式
144
+
145
+ ```text
146
+ {主题域}{分析焦点}{Cube|Analytics}
147
+ ```
148
+
149
+ | 规则 | 说明 |
150
+ | ---- | ---- |
151
+ | **PascalCase** | `SalesCube`、`ProductSalesCube` |
152
+ | **后缀** | 推荐 **`Cube`**(与平台 `register_cube` 一致);可选 `Analytics`(如 `SalesAnalytics`),**同一实现单元内统一一种** |
153
+ | **禁止** | 与对象 `code` 完全相同(`Product` ≠ Cube 名);与物理表名相同(`dim_product`) |
154
+ | **qualified_name** | 成员为 `CubeName.member`(如 `SalesCube.sales_amount`) |
155
+
156
+ ### 4.2 Cube 类别
157
+
158
+ | 类别 | 用途 | 事实源 | 命名示例 |
159
+ | ---- | ---- | ------ | -------- |
160
+ | **流程型 Process** | 以事务/事件为主线,多维度切片 | 主 `fact_*` | `SalesCube`、`GlJournalCube` |
161
+ | **主体型 Subject** | 以单一业务主体聚合(产品/客户/科目) | 同一 fact 或 subject 切片 | `ProductSalesCube`、`CustomerSalesCube` |
162
+ | **对比型 Comparison** | 预实、同比口径、A/B 版本 | 多个 fact 或带 version 维 | `BudgetVsActualCube` |
163
+ | **快照型 Snapshot** | 时点库存、余额(非可加事件) | 快照 fact 或 agg | `InventorySnapshotCube` |
164
+ | **时间增强** | 时间智能(通常 **不单独建 Cube**) | 通过 **`dim_date`** JOIN 进 Process/Subject Cube | 优先在 `SalesCube` 上挂 `year`/`month`/`fiscal_period` 维,而非孤立 `TimeSalesCube` |
165
+
166
+ > **建议**:旧示例中的 `TimeSalesCube` 在新规范下 **合并进 Process Cube** + **`dim_date`**;仅当时间主题完全独立(如专用日历配置分析)才保留独立 Cube。
167
+
168
+ ### 4.3 每个 Cube 规划必写
169
+
170
+ | 列 | 说明 |
171
+ | -- | ---- |
172
+ | Cube 名 | 符合 §4.1 |
173
+ | **类别** | Process / Subject / Comparison / Snapshot |
174
+ | 事实源表 | 主 `fact_*` 表名 |
175
+ | 时间维 | 是否 JOIN `dim_date`;时间成员来自哪些列 |
176
+ | 维度 | GROUP BY / 筛选字段 |
177
+ | 度量 | 列名、聚合、业务含义 |
178
+ | 派生度量 | 表达式与口径 |
179
+ | **支撑的对象类型** | 哪些对象 `bind_source` 绑定本 Cube |
180
+
181
+ ### 4.4 Cube 与多对象
182
+
183
+ - **多对象可绑同一 Cube**(如 `SalesOrder` 与 `SalesAnalysis` 均绑 `SalesCube`,属性映射不同)
184
+ - **一对象只绑一个主 Cube**(读模型);明细补全可在函数 SQL 中 JOIN `dim_*`
185
+ - 同一 `fact_*` 可注册 **多个 Cube**(不同维度切片)
186
+
187
+ ---
188
+
189
+ ## 5. 本体对象:Palantir 思想与分类
190
+
191
+ ### 5.1 与 Palantir Foundry Ontology 的对照
192
+
193
+ | Palantir 概念 | 搭子平台 | 命名要点 |
194
+ | ------------- | -------- | -------- |
195
+ | **Object Type** | `define_object_type(code, name, ...)` | **`code` 无前缀**,PascalCase 单数业务名 |
196
+ | **Property** | `define_property` | 业务属性名;度量/维度带 Cube `qualified_name` |
197
+ | **Link Type** | `define_link_type` | 业务关系语义,非表 FK 名 |
198
+ | **Action Type** | `define_action` | 动词短语 code |
199
+ | **Function** | `register_function` / 函数脚本 | `domain.fn.name`(带点号命名空间) |
200
+
201
+ **核心思想**(规划阶段强制):
202
+
203
+ - 对象类型描述 **业务世界中「是什么」**,不是「哪张表」
204
+ - **先对象与链接,后表与 Cube**;允许多表/多 Cube 支撑一对象,也允许多对象视角看同一 fact
205
+ - 对象 **`code` 不加 `dim_` / `fact_` / `Obj` 前缀**;分类用 **文档标签 + 规划表格**,不写入 `code`
206
+
207
+ ### 5.2 对象类型 code 格式
208
+
209
+ ```text
210
+ {BusinessNoun} # PascalCase,英文单数为主
211
+ {BusinessNoun}{Role} # 必要时消歧,如 BudgetLine、SalesOrderLine
212
+ ```
213
+
214
+ | 规则 | 正确 | 错误 |
215
+ | ---- | ---- | ---- |
216
+ | 业务名词 | `Product`, `Customer`, `SalesOrder` | `dim_product`, `ProductObject` |
217
+ | 稳定标识 | `JournalEntry`, `Account` | `TblAccount`, `FactSales` |
218
+ | 与表/Cube 区分 | `Product` + `ProductSalesCube` + `dim_product` | 三者同名 |
219
+
220
+ **中文 `name`**:面向业务用户(产品、客户、销售订单);**`code`**:面向 API / 脚本 / 链接引用。
221
+
222
+ ### 5.3 对象分类(无 code 前缀)
223
+
224
+ 规划文档中为每个对象类型标注 **以下一类**(可多标签,但须有一个主分类):
225
+
226
+ | 分类 | 英文标签 | 业务含义 | 典型对象 | 读模型来源 |
227
+ | ---- | -------- | -------- | -------- | ---------- |
228
+ | **主数据** | `Master` | 长期存在、可被多次引用 | `Product`, `Customer`, `Account`, `CostCenter` | Subject Cube 或 `dim_*` + 函数补全 |
229
+ | **事务/事件** | `Transaction` | 一次业务发生、有时间性 | `SalesOrder`, `JournalEntry`, `BudgetLine` | Process Cube / 主 `fact_*` |
230
+ | **分析上下文** | `Analytical` | 分析会话/切片上的「上下文对象」,非 ERP 主数据 | `SalesAnalysis`, `ProfitAnalysis` | Process Cube(常无独立 `dim_*`) |
231
+ | **参考** | `Reference` | 枚举型、码表级、体量小 | `Channel`, `Currency`, `OrderStatus` | `dim_*` 或 Cube 维度 |
232
+ | **配置** | `Configuration` | 版本、日历、口径规则 | `BudgetVersion`, `FiscalCalendar` | `cfg_*` 或专用 dim |
233
+
234
+ **Palantir 式自检**:
235
+
236
+ - 能否用 **一句业务话** 向非技术人员解释该对象?(「销售订单是一次成交记录」✓)
237
+ - 链接是否表达 **业务关系** 而非「表 A 的 id 等于表 B 的 id」?
238
+ - Action/Function 是否挂在 **对象** 上,而非挂在表名上?
239
+
240
+ ### 5.4 bind_source 约定
241
+
242
+ | 对象分类 | 典型 bind_source |
243
+ | -------- | ---------------- |
244
+ | Master / Reference | Subject Cube 或 Process Cube 的子集 |
245
+ | Transaction | Process Cube |
246
+ | Analytical | Process Cube(同一 fact,属性偏度量/筛选) |
247
+ | Configuration | 可无 Cube;函数直读 `cfg_*` / `dim_*` |
248
+
249
+ 规划须有 **对象 → Cube → 主 fact/dim** 对照表(见 §7)。
250
+
251
+ ### 5.5 本体函数 function_id(补充)
252
+
253
+ 对象 **`code` 无前缀**;函数仍用 **命名空间**(与 Palantir Function 类似):
254
+
255
+ ```text
256
+ {domain}.fn.{action_name} # 如 sales.fn.get_summary, profit.fn.yoy_analysis
257
+ {domain}.action.{code} # Action 脚本注册
258
+ ```
259
+
260
+ ---
261
+
262
+ ## 6. 链接类型命名
263
+
264
+ 链接描述 **对象之间** 的有向业务关系;与物理表 `add_relationship` **分层**,但应 **可对照**。
265
+
266
+ ### 6.1 格式
267
+
268
+ ```text
269
+ {from_role}_{verb}_{to_role} # snake_case
270
+ {verb}_{to_role} # 简式(from 在 define_link_type 参数中已体现)
271
+ ```
272
+
273
+ | 规则 | 示例 |
274
+ | ---- | ---- |
275
+ | 业务动词/介词 | `order_contains_product`, `entry_posts_to_account` |
276
+ | 基数在 API 参数中声明 | `define_link_type(..., cardinality=...)` |
277
+ | 禁止 | `product_id_fk`, `rel_sales_product`(物理层命名) |
278
+
279
+ ### 6.2 与表间关系对照
280
+
281
+ | 物理关系 | 本体链接(示例) |
282
+ | -------- | ---------------- |
283
+ | `fact_sales_order_line` → `dim_product` | `SalesOrder` —*contains*→ `Product` |
284
+ | `fact_sales_order_line` → `dim_customer` | `SalesOrder` —*sold_to*→ `Customer` |
285
+ | `fact_gl_journal_entry` → `dim_account` | `JournalEntry` —*posts_to*→ `Account` |
286
+
287
+ ---
288
+
289
+ ## 7. 三层对照与迁移示例(销售域)
290
+
291
+ ### 7.1 旧名 → 新名(物理表)
292
+
293
+ | 现名(不规范) | 新名 | 类别 |
294
+ | -------------- | ---- | ---- |
295
+ | — | **`dim_date`** | 时间维(**新增**) |
296
+ | `product_master` | `dim_product` | 维 |
297
+ | `customer_dimension` | `dim_customer` | 维 |
298
+ | `channel_dimension` | `dim_channel` | 维 |
299
+ | `sales_order_fact` | `fact_sales_order_line` | 事实(订单行粒度) |
300
+
301
+ **`fact_sales_order_line` 增补**:`date_key Int32` → `dim_date.date_key`
302
+
303
+ ### 7.2 Cube(建议)
304
+
305
+ | 现 Cube | 类别 | 建议调整 |
306
+ | ------- | ---- | -------- |
307
+ | `SalesCube` | Process | 保留;事实源改为 `fact_sales_order_line`;时间维来自 **`dim_date`** |
308
+ | `ProductSalesCube` | Subject | 保留 |
309
+ | `CustomerSalesCube` | Subject | 保留 |
310
+ | `ChannelSalesCube` | Subject | 保留 |
311
+ | `TimeSalesCube` | — | **合并**进 `SalesCube`(`dim_date` 列),或标注 deprecated |
312
+
313
+ ### 7.3 本体对象(基本不变,补分类)
314
+
315
+ | code | 分类 | bind_source | 主物理支撑 |
316
+ | ---- | ---- | ----------- | ---------- |
317
+ | `Product` | Master | `ProductSalesCube` | `dim_product` |
318
+ | `Customer` | Master | `CustomerSalesCube` | `dim_customer` |
319
+ | `Channel` | Reference | `ChannelSalesCube` | `dim_channel` |
320
+ | `SalesOrder` | Transaction | `SalesCube` | `fact_sales_order_line` |
321
+ | `SalesAnalysis` | Analytical | `SalesCube` | 同 fact |
322
+
323
+ ### 7.4 利润域(摘要)
324
+
325
+ | 物理(新) | Cube(示例) | 对象(示例) |
326
+ | ---------- | ------------ | ------------ |
327
+ | `dim_date`, `dim_account`, `dim_cost_center` | `GlJournalCube`, `BudgetCube` | `Account`, `CostCenter` |
328
+ | `fact_gl_journal_entry`, `fact_budget_entry` | `ActualCube`, `BudgetVsActualCube` | `JournalEntry`, `BudgetLine` |
329
+
330
+ ---
331
+
332
+ ## 8. 规划文档写法与自检清单
333
+
334
+ ### 8.1 物理层章节结构(建议)
335
+
336
+ ```markdown
337
+ ### 3.0 时间维(强制)
338
+ ### 3.1 事实表(fact_*)
339
+ ### 3.2 维度表(dim_*)
340
+ ### 3.3 桥表 / 映射 / 配置 / 汇总(按需)
341
+ ### 3.x 表间关系(含 fact → dim_date)
342
+ ```
343
+
344
+ ### 8.2 Cube 层章节结构(建议)
345
+
346
+ ```markdown
347
+ ## 四、Cube 层设计
348
+ ### 4.0 Cube 清单与类别
349
+ | Cube | 类别 | 事实源 | 支撑对象 |
350
+ ### 4.1 SalesCube(Process)…
351
+ ```
352
+
353
+ ### 8.3 本体层章节结构(建议)
354
+
355
+ ```markdown
356
+ ## 五、本体层设计
357
+ ### 5.1 对象类型清单
358
+ | code | 分类 | name | bind_source |
359
+ ### 5.2 对象属性 …
360
+ ### 5.3 链接类型 …
361
+ ### 5.4 三层对照总表
362
+ | 对象 code | 分类 | Cube | 主 fact/dim |
363
+ ```
364
+
365
+ ### 8.4 自检清单(在 [本体规划指南](./本体规划指南.md) 原 10 项基础上扩展)
366
+
367
+ | # | 检查项 | 通过标准 |
368
+ | - | ------ | -------- |
369
+ | 2a | **dim_date** | 含 `dim_date`,PK 为 **`date_key`** |
370
+ | 2b | **fact 时间键** | 每张 `fact_*` 含 **`date_key`** 并关联 `dim_date` |
371
+ | 2c | **表前缀** | 使用 `fact_`/`dim_`/…,无 `_master`、`_dimension` 混用 |
372
+ | 4a | **Cube 类别** | 每个 Cube 标注 Process/Subject/Comparison/Snapshot |
373
+ | 4b | **Cube 命名** | PascalCase + `Cube` 后缀;不与对象 code 同名 |
374
+ | 5a | **对象分类** | 每个对象类型标注 Master/Transaction/Analytical/Reference/Configuration |
375
+ | 5b | **对象 code** | PascalCase **无前缀**;与表名/Cube 名区分 |
376
+ | 5c | **三层对照** | 附录含 对象↔Cube↔表 对照 |
377
+ | 6a | **CATEGORY_REGISTRY** | 规划附录 B 与 init 顶部字典一致(见 [349](./本体分类规划与SDK扩展方案.md)) |
378
+ | 6b | **表平台分类** | 每张表标注 347 标准中文名(时间维/维度表/事实表等) |
379
+ | 6c | **Cube 平台分类** | 每个 Cube 标注 流程型/主体型/对比型/快照型 |
380
+ | 6d | **对象/链接/关系分类** | 对象标 主数据/事务/分析/参考;链接与关系标扩展类别 |
381
+ | 6e | **分类挂载** | init 含 `apply_registry` 或注册时 `category_347=`;侧栏与 347 一致 |
382
+
383
+ ---
384
+
385
+ ## 9. 相关文档索引
386
+
387
+ | 文档 | 说明 |
388
+ | ---- | ---- |
389
+ | [本体规划指南](./本体规划指南.md) | 规划章节、Cube 强制、自检 |
390
+ | [规划示例:产品销售](./规划示例_产品销售本体规划方案.md) | 完整示例(待按本规范修订表名) |
391
+ | [规划示例:利润分析](./规划示例_利润分析本体方案.md) | GL 域示例(待修订) |
392
+ | [DaziScript SDK 参考](./dazi_script_sdk_reference.md) | `register_cube`、`define_object_type` API |
393
+ | [本体脚本编写指南](./本体脚本编写指南.md) | init / seed / 表间关系实施 |
394
+ | [349 · 本体分类规划与 SDK 扩展方案](./本体分类规划与SDK扩展方案.md) | 平台分类与 CATEGORY_REGISTRY |
395
+
396
+ ---
397
+
398
+ **变更记录**
399
+
400
+ | 日期 | 说明 |
401
+ | ---- | ---- |
402
+ | 2026-06-05 | 首版:物理表 7 类 + dim_date;Cube 4+1 类;本体对象 Palantir 式 5 分类;三层对照与自检扩展 |
@@ -6,6 +6,16 @@
6
6
 
7
7
  > 终端命令均在 **`dazi-work` 根目录**执行:`dazi ...`(见 [CLI 调用约定](../guides/cli-invocation.md))。
8
8
 
9
+ ## 执行脚本前必读(强制)
10
+
11
+ 在终端执行 **`dazi onto script publish` / `script run` / `function run` / `save-test-arguments`** 之前,**必须**阅读:
12
+
13
+ | 文档 | 说明 |
14
+ | ---- | ---- |
15
+ | **[脚本运行纠错(商务成本实录)](./脚本运行纠错_商务成本方案开发过程.md)** | setup API 误用、`query_one` 聚合陷阱、**函数禁止 `output.print_json()`**、CLI 参数(`function run` 不支持 JSON 文件、`save-test-arguments` 须 `ofn_xxx`) |
16
+
17
+ `dazi docs show onto/script-run-troubleshooting` · 智能体另见提示词 **`onto/script-publish-run`**。
18
+
9
19
  ## 环境
10
20
 
11
21
  - 推荐 **Python 3.10+**
@@ -58,10 +68,11 @@
58
68
  | 步骤 | 内容 | API |
59
69
  | ---- | ---- | --- |
60
70
  | 1 | 建表 | `s.sql.execute(CREATE TABLE ...)` |
61
- | 2 | 注册表 | `s.tables.register` + `s.tables.sync_columns` |
71
+ | 2 | 注册表 | `s.tables.register_with_meta`(含表/列 `display_name`、`description`) |
62
72
  | 3 | **注册表间关系** | `s.tables.add_relationship(...)` |
63
73
  | 4 | 注册 Cube / 派生度量 | `s.register_cube`、`s.upsert_derived_measures` |
64
74
  | 5 | 本体对象 / 属性 / 链接 | `s.onto.define_*`、`s.sync_metric_refs` |
75
+ | 6 | **347 对齐分类** | `s.categories.apply_registry(CATEGORY_REGISTRY, skip_missing=True)` |
65
76
 
66
77
  ### 表间关系 `s.tables.add_relationship`
67
78
 
@@ -82,6 +93,50 @@ s.tables.add_relationship(
82
93
 
83
94
  > **勿与** `s.onto.define_link_type` 混淆:前者写数据空间元数据,后者写业务对象语义链接,**两者都需实施**。
84
95
 
96
+ ### 表注册 `TABLE_REGISTRY` + `register_with_meta`
97
+
98
+ init 脚本顶部维护与规划文档对齐的 `TABLE_REGISTRY`(项目内 `plans/*.md` 或内置 [规划示例](./规划示例_产品销售本体规划方案.md)),步骤 2 统一调用:
99
+
100
+ ```python
101
+ TABLE_REGISTRY = {
102
+ "fact_sales_order_line": {
103
+ "display_name": "销售订单行事实表",
104
+ "description": "订单行粒度销售流水",
105
+ "columns": [
106
+ {"name": "order_id", "display_name": "订单 ID"},
107
+ {"name": "date_key", "display_name": "日期键", "description": "关联 dim_date"},
108
+ # ...
109
+ ],
110
+ },
111
+ }
112
+
113
+ for tbl_name, meta in TABLE_REGISTRY.items():
114
+ s.tables.register_with_meta(
115
+ table_name=tbl_name,
116
+ display_name=meta["display_name"],
117
+ description=meta.get("description"),
118
+ columns=meta["columns"],
119
+ force_column_meta=True, # 规划变更后重跑 init 时刷新列元数据
120
+ )
121
+ ```
122
+
123
+ - **显示名** → 侧栏与表预览列标题(`display_name`)
124
+ - **说明** → 业务口径、FK、冗余原因(`description`);`sync_columns` **不会**自动写入
125
+ - 参考:`资源/examples/onto/利润示例/setup/profit_ontology_init.py`、`销售示例/setup/sales_ontology_init.py`
126
+
127
+ ### 分类注册 `CATEGORY_REGISTRY` + `apply_registry`
128
+
129
+ init 脚本顶部维护与规划附录 B 对齐的 `CATEGORY_REGISTRY`(分类名必须是 [347](./本体命名规范_物理表Cube与对象.md) 标准中文名),**所有资源注册完成后**调用:
130
+
131
+ ```python
132
+ cat_counts = s.categories.apply_registry(CATEGORY_REGISTRY, skip_missing=True)
133
+ ```
134
+
135
+ - 6 类资源平级挂载:`table` / `cube` / `object` / `relation` / `link` / `function`
136
+ - 函数类资源若 init 未 `register_function`,须 `skip_missing=True`
137
+ - 可选:注册 API 传 `category_347="维度表"` 等即时挂载(与 `apply_registry` 幂等可并存)
138
+ - 详见 [349 方案](./本体分类规划与SDK扩展方案.md)、[SDK 参考 §5.6](./dazi_script_sdk_reference.md)
139
+
85
140
  ## 脚本类型
86
141
 
87
142
  类型由 **发布命令参数** 区分;初始化与灌数放 `setup/`,本体函数与动作放 `functions/`:
@@ -108,6 +163,8 @@ dazi onto script publish-preview 项目/<业务名>/本体/ontos/<实现名>/fun
108
163
 
109
164
  `functions/`(或规划中的本体函数 `.py`)**不能**只执行「普通 publish」:
110
165
 
166
+ **新建函数**:复制 `资源/examples/onto/_templates/ontology_function_template.py`(`dazi examples show onto/template/ontology-function`),或参考 `销售示例/functions/sales_fn_get_summary.py`。`main()` **无参**,业务写在 `_ontology_fn_body(p)`,末尾 **`return _ontology_fn_body(p)`** — **禁止** `output.print_json()`(见 [脚本运行纠错 §3](./脚本运行纠错_商务成本方案开发过程.md#3-函数输出方式错误outputprint_json))。
167
+
111
168
  | 仅 `script publish`(无 `--register-function-id`) | 带 `--register-function-id` 发布 |
112
169
  | -------------------------------------------------- | -------------------------------------------- |
113
170
  | 脚本代码进入 `ads_scripts` | 同上 **且** 写入 `ontology_function_defs` |
@@ -152,6 +209,8 @@ dazi onto function run sales.fn.get_summary --space <space-id> --params '{}'
152
209
 
153
210
  仅 `publish` + `function run` **不会**自动写入测试参数;侧栏 **Onto → 运行函数** 依赖函数定义上的 **`test_arguments`** 预填表单。
154
211
 
212
+ > **CLI 易错点**:`function run` **不支持** `--arguments-json-file`;`save-test-arguments` 须用 **`ofn_xxx` 内部 id** 而非 `function_id` 字符串。完整说明见 [脚本运行纠错](./脚本运行纠错_商务成本方案开发过程.md)。
213
+
155
214
  **本地约定(与规划文档 § 函数 / test_arguments 一致)**:
156
215
 
157
216
  1. 每个函数一份 JSON:`functions/test_arguments/<function_id>.json`
@@ -235,6 +294,7 @@ dazi onto script dedupe --space <space-id> --yes
235
294
  | ------ | ----------- |
236
295
  | 表已注册 | 侧栏 **数据资源** 或 `dazi onto space get` → `table_count` |
237
296
  | **表间关系已注册** | `relationship_count` > 0;侧栏 **表间关系** |
297
+ | **347 分类已挂载** | 侧栏分类视图下表/Cube/对象等按标准中文名分组;init 摘要含 `category_mounts` |
238
298
  | 函数已注册 | `dazi onto function list --space <space-id>` |
239
299
  | **test_arguments 已保存** | `dazi onto function get <function_id>` → `test_arguments.arguments` |
240
300
  | 函数可运行 | `dazi onto function run <function_id> --space <space-id> --params '{}'` |
@@ -247,3 +307,5 @@ dazi onto script dedupe --space <space-id> --yes
247
307
  - [本体动作开发](./action-guide.md)
248
308
  - [规划示例:产品销售本体(推荐)](./规划示例_产品销售本体规划方案.md)
249
309
  - [规划示例:利润分析本体(补充)](./规划示例_利润分析本体方案.md)
310
+ - [349 · 本体分类规划与 SDK 扩展方案](./本体分类规划与SDK扩展方案.md)
311
+ - [脚本运行纠错(商务成本方案实录)](./脚本运行纠错_商务成本方案开发过程.md)