@dazitech/cli 3.0.6 → 3.0.8
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.
- package/README.md +1 -1
- package/dist/clis/dazi-app.js +1 -1
- package/dist/clis/dazi-flow.js +43 -24
- package/dist/clis/dazi-onto.js +73 -22
- package/dist/clis/dazi.js +266 -171
- package/dist/docs/flow/ai-workflow-playbook.md +4 -2
- package/dist/docs/flow/flow-project-guide.md +9 -5
- package/dist/docs/flow/flows-guide.md +2 -2
- package/dist/docs/flow/node-code-guide.md +408 -401
- package/dist/docs/flow/run-guide.md +13 -6
- package/dist/docs/flow/variables-guide.md +407 -406
- package/dist/docs/guides/quickstart.md +18 -4
- package/dist/docs/guides/troubleshooting.md +1 -1
- package/dist/docs/guides/workspace-v3.md +43 -23
- package/dist/docs/index.json +9 -3
- package/dist/docs/onto/action-guide.md +3 -3
- package/dist/docs/onto/dazi_script_sdk_reference.md +178 -174
- package/dist/docs/onto/dazi_script_seed_data_guide.md +158 -155
- package/dist/docs/onto/function-guide.md +37 -10
- package/dist/docs/onto/space-management.md +3 -1
- 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 +138 -34
- package/dist/docs/onto//346/234/254/344/275/223/350/247/204/345/210/222/346/214/207/345/215/227.md +73 -31
- 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 +497 -0
- 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 +597 -541
- package/dist/examples/index.json +202 -22
- package/dist/examples/onto/README.md +43 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_account_breakdown.py +99 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_budget_vs_actual.py +116 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_cost_center_profit.py +85 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_get_summary.py +76 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_mom_analysis.py +86 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_top_accounts.py +103 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_yoy_analysis.py +86 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/save_test_arguments.ps1 +27 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.account_breakdown.json +10 -0
- 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 +10 -0
- 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 +9 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.get_summary.json +9 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.mom_analysis.json +9 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.top_accounts.json +11 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.yoy_analysis.json +9 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_ontology_init.py +521 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_seed_data.py +213 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/README.md +25 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_channel_mix.py +86 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_customer_segmentation.py +123 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_get_summary.py +81 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_mom_analysis.py +90 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_region_breakdown.py +85 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_top_products.py +101 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_yoy_analysis.py +90 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/save_test_arguments.ps1 +25 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.channel_mix.json +8 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.customer_segmentation.json +10 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.get_summary.json +8 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.mom_analysis.json +8 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.region_breakdown.json +8 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.top_products.json +10 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.yoy_analysis.json +8 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/README.md +5 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_ontology_init.py +403 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_seed_data.py +124 -0
- package/dist/prompts/flow/ai-workflow-playbook.md +4 -2
- package/dist/prompts/flow/flow-design.md +12 -9
- package/dist/prompts/flow/run-fix-loop.md +37 -22
- package/dist/prompts/index.json +2 -2
- package/dist/prompts/onto/action-design.md +4 -1
- package/dist/prompts/onto/function-design.md +9 -2
- package/dist/prompts/onto/rule-seed.md +5 -1
- package/dist/prompts/onto/script-publish-run.md +72 -24
- package/package.json +1 -1
- package/dist/examples/onto/function/profit_fn_customer_segmentation.py +0 -117
- package/dist/examples/onto/function/profit_fn_mom_analysis.py +0 -89
- package/dist/examples/onto/function/profit_fn_top_products.py +0 -89
- package/dist/examples/onto/function/profit_fn_yoy_analysis.py +0 -89
- package/dist/examples/onto/setup/profit_ontology_init.py +0 -388
|
@@ -2,36 +2,47 @@
|
|
|
2
2
|
|
|
3
3
|
**文档 ID**: `onto/script-authoring`
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
本文说明本体实现单元内 **Python 脚本的目录、类型、发布与运行**(原独立的「脚本开发与发布」已与本文合并)。
|
|
6
6
|
|
|
7
7
|
> 终端命令均在 **`dazi-work` 根目录**执行:`dazi ...`(见 [CLI 调用约定](../guides/cli-invocation.md))。
|
|
8
8
|
|
|
9
9
|
## 环境
|
|
10
10
|
|
|
11
11
|
- 推荐 **Python 3.10+**
|
|
12
|
-
-
|
|
12
|
+
- 脚本目录:**`<工作区根>/项目/<业务名>/本体/ontos/<实现名>/setup/`** 与 **`functions/`**(新建本体实现时自动创建)
|
|
13
13
|
- 扩展默认脚本语言:`dazi.onto.defaultScriptLang` = `python`
|
|
14
14
|
- 平台 API:`dazi.serverUrl`;登录:`dazi auth login` / `dazi auth set-token`
|
|
15
15
|
|
|
16
16
|
## 目录约定
|
|
17
17
|
|
|
18
18
|
```text
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
├──
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
<工作区根>/项目/<业务名>/ ← 业务项目根
|
|
20
|
+
└── 本体/
|
|
21
|
+
└── ontos/<实现名>/ ← 本体实现单元;README 含 space_id
|
|
22
|
+
├── README.md
|
|
23
|
+
├── 快速启动_<实现名>.md
|
|
24
|
+
├── plans/ ← 规划阶段 Markdown 产出
|
|
25
|
+
├── setup/ ← 初始化、灌数脚本
|
|
26
|
+
└── functions/ ← 本体函数、动作脚本
|
|
27
|
+
├── test_arguments/ ← 各 function_id 的 test_arguments JSON
|
|
28
|
+
├── save_test_arguments.ps1 ← 可选:批量写入平台(推荐)
|
|
29
|
+
└── *.py
|
|
26
30
|
```
|
|
27
31
|
|
|
28
|
-
参考示例(可复制后修改)位于 **`资源/examples/onto
|
|
32
|
+
参考示例(可复制后修改)位于 **`资源/examples/onto/`**,按 **利润示例**、**销售示例** 两套打包(侧栏 **帮助 → 示例** 或 `dazi examples sync`)。
|
|
29
33
|
|
|
30
|
-
|
|
34
|
+
| 示例包 | 目录 | 规划文档 | 主要内容 |
|
|
35
|
+
|--------|------|----------|----------|
|
|
36
|
+
| **销售示例**(推荐) | `onto/销售示例/` | [规划示例_产品销售本体规划方案](./规划示例_产品销售本体规划方案.md) | `setup/sales_ontology_init.py`、`sales_seed_data.py`、7 个 `sales_fn_*.py`、`test_arguments/` |
|
|
37
|
+
| **利润示例**(补充) | `onto/利润示例/` | [规划示例_利润分析本体方案](./规划示例_利润分析本体方案.md) | `setup/profit_ontology_init.py`、`profit_seed_data.py`、7 个 `profit_fn_*.py`、`test_arguments/` |
|
|
38
|
+
|
|
39
|
+
总览说明:`资源/examples/onto/README.md`(`dazi examples show onto/readme`)。
|
|
40
|
+
|
|
41
|
+
> **不再使用** 历史路径 `onto/<space_id>/editorial/`、`editorial/functions/`、`项目/onto_<名称>/脚本/` 等作为本地开发约定。
|
|
31
42
|
|
|
32
43
|
## 必读规范(DaziScript)
|
|
33
44
|
|
|
34
|
-
编写
|
|
45
|
+
编写 `setup/`、`functions/` 下 `.py` 前请阅读:
|
|
35
46
|
|
|
36
47
|
| 文档 | 说明 |
|
|
37
48
|
| ------------------------------------------------------------------- | ---------------------------------------------------------------------- |
|
|
@@ -40,22 +51,53 @@
|
|
|
40
51
|
|
|
41
52
|
同步到工作区:`dazi docs sync` → `资源/docs/onto/`。
|
|
42
53
|
|
|
54
|
+
## 初始化脚本标准顺序(setup)
|
|
55
|
+
|
|
56
|
+
`*_ontology_init.py` 建议按以下顺序执行(与 [本体规划指南](./本体规划指南.md) 物理层 + 表间关系章节一致):
|
|
57
|
+
|
|
58
|
+
| 步骤 | 内容 | API |
|
|
59
|
+
| ---- | ---- | --- |
|
|
60
|
+
| 1 | 建表 | `s.sql.execute(CREATE TABLE ...)` |
|
|
61
|
+
| 2 | 注册表 | `s.tables.register` + `s.tables.sync_columns` |
|
|
62
|
+
| 3 | **注册表间关系** | `s.tables.add_relationship(...)` |
|
|
63
|
+
| 4 | 注册 Cube / 派生度量 | `s.register_cube`、`s.upsert_derived_measures` |
|
|
64
|
+
| 5 | 本体对象 / 属性 / 链接 | `s.onto.define_*`、`s.sync_metric_refs` |
|
|
65
|
+
|
|
66
|
+
### 表间关系 `s.tables.add_relationship`
|
|
67
|
+
|
|
68
|
+
在 **表 register 完成之后、Cube 注册之前** 调用;**幂等**,可重复执行 init。
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
s.tables.add_relationship(
|
|
72
|
+
from_table="sales_order_fact", # 通常为事实表
|
|
73
|
+
to_table="product_master", # 维表
|
|
74
|
+
join_sql="sales_order_fact.product_id = product_master.product_id",
|
|
75
|
+
join_keys=[{"from": "product_id", "to": "product_id"}],
|
|
76
|
+
relationship_type="many_to_one", # 默认 many_to_one
|
|
77
|
+
description="销售订单行关联产品主数据",
|
|
78
|
+
)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
验收:`dazi onto space get <space-id>` 中 **`relationship_count`** 与规划条数一致;侧栏 **数据资源 → 表间关系** 可见。
|
|
82
|
+
|
|
83
|
+
> **勿与** `s.onto.define_link_type` 混淆:前者写数据空间元数据,后者写业务对象语义链接,**两者都需实施**。
|
|
84
|
+
|
|
43
85
|
## 脚本类型
|
|
44
86
|
|
|
45
|
-
类型由 **发布命令参数**
|
|
87
|
+
类型由 **发布命令参数** 区分;初始化与灌数放 `setup/`,本体函数与动作放 `functions/`:
|
|
46
88
|
|
|
47
|
-
| 类型 | 路径约定
|
|
48
|
-
| ------------------- |
|
|
49
|
-
| `ontology_function` |
|
|
50
|
-
| `ontology_action` |
|
|
51
|
-
| `data_script` |
|
|
89
|
+
| 类型 | 路径约定 | 说明 |
|
|
90
|
+
| ------------------- | ----------------------------------------------------------------- | -------------------------------------------------- |
|
|
91
|
+
| `ontology_function` | `项目/<业务名>/本体/ontos/<实现名>/functions/**/*.py` | **必须**带 `--register-function-id` 发布(见下节) |
|
|
92
|
+
| `ontology_action` | `项目/<业务名>/本体/ontos/<实现名>/functions/**/*.py` | 发布时加 `--register-action-id` 等 Action 参数 |
|
|
93
|
+
| `data_script` | `项目/<业务名>/本体/ontos/<实现名>/setup/**/*.py` | 普通 `script publish`,不注册函数/动作 |
|
|
52
94
|
|
|
53
|
-
`<space-id>` 从
|
|
95
|
+
`<space-id>` 从 **`项目/<业务名>/本体/ontos/<实现名>/README.md`** 读取,勿手写错空间。
|
|
54
96
|
|
|
55
97
|
## 发布预检
|
|
56
98
|
|
|
57
99
|
```powershell
|
|
58
|
-
dazi onto script publish-preview
|
|
100
|
+
dazi onto script publish-preview 项目/<业务名>/本体/ontos/<实现名>/functions/my_func.py --space <space-id>
|
|
59
101
|
```
|
|
60
102
|
|
|
61
103
|
## 发布脚本
|
|
@@ -64,7 +106,7 @@ dazi onto script publish-preview 项目/onto_<项目名>/脚本/my_func.py --spa
|
|
|
64
106
|
|
|
65
107
|
### 本体函数:**必须注册**,否则侧栏与测试看不到
|
|
66
108
|
|
|
67
|
-
|
|
109
|
+
`functions/`(或规划中的本体函数 `.py`)**不能**只执行「普通 publish」:
|
|
68
110
|
|
|
69
111
|
| 仅 `script publish`(无 `--register-function-id`) | 带 `--register-function-id` 发布 |
|
|
70
112
|
| -------------------------------------------------- | -------------------------------------------- |
|
|
@@ -84,16 +126,16 @@ dazi onto script publish-preview 项目/onto_<项目名>/脚本/my_func.py --spa
|
|
|
84
126
|
|
|
85
127
|
```powershell
|
|
86
128
|
# 初始化 / 灌数:普通发布即可(不要加 register-function-id)
|
|
87
|
-
dazi onto script publish
|
|
88
|
-
dazi onto script publish
|
|
129
|
+
dazi onto script publish 项目/<业务名>/本体/ontos/<实现名>/setup/xxx_ontology_init.py --space <space-id> --type setup
|
|
130
|
+
dazi onto script publish 项目/<业务名>/本体/ontos/<实现名>/setup/xxx_seed_data.py --space <space-id> --type data
|
|
89
131
|
|
|
90
132
|
# ★ 本体函数:必须注册(示例)
|
|
91
|
-
dazi onto script publish
|
|
133
|
+
dazi onto script publish 项目/<业务名>/本体/ontos/<实现名>/functions/get_summary.py `
|
|
92
134
|
--space <space-id> `
|
|
93
135
|
--register-function-id sales.fn.get_summary
|
|
94
136
|
|
|
95
137
|
# 发布并注册为本体动作(示例)
|
|
96
|
-
dazi onto script publish
|
|
138
|
+
dazi onto script publish 项目/<业务名>/本体/ontos/<实现名>/functions/my_action.py `
|
|
97
139
|
--space <space-id> `
|
|
98
140
|
--register-action-id my_action_code `
|
|
99
141
|
--register-action-permission-tag "finance.write"
|
|
@@ -103,9 +145,55 @@ dazi onto script publish 项目/onto_<项目名>/脚本/my_action.py `
|
|
|
103
145
|
|
|
104
146
|
```powershell
|
|
105
147
|
dazi onto function list --space <space-id>
|
|
106
|
-
dazi onto function run sales.fn.get_summary --space <space-id>
|
|
148
|
+
dazi onto function run sales.fn.get_summary --space <space-id> --params '{}'
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### 函数测试参数(test_arguments,**发布后必做**)
|
|
152
|
+
|
|
153
|
+
仅 `publish` + `function run` **不会**自动写入测试参数;侧栏 **Onto → 运行函数** 依赖函数定义上的 **`test_arguments`** 预填表单。
|
|
154
|
+
|
|
155
|
+
**本地约定(与规划文档 § 函数 / test_arguments 一致)**:
|
|
156
|
+
|
|
157
|
+
1. 每个函数一份 JSON:`functions/test_arguments/<function_id>.json`
|
|
158
|
+
2. 脚本内同名常量 `TEST_ARGUMENTS`(与 JSON **保持同步**)
|
|
159
|
+
3. 函数 `main()` 通过 `ctx.params` 读取的键名 = JSON 内 **`arguments`** 对象的键名
|
|
160
|
+
|
|
161
|
+
**JSON 格式**(与平台函数定义一致):
|
|
162
|
+
|
|
163
|
+
```json
|
|
164
|
+
{
|
|
165
|
+
"v": 1,
|
|
166
|
+
"arguments": {
|
|
167
|
+
"start_date": "2025-01-01",
|
|
168
|
+
"end_date": "2026-06-30"
|
|
169
|
+
},
|
|
170
|
+
"object_type_code": "SalesAnalysis"
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**保存到平台**(函数 `run` 验证通过后):
|
|
175
|
+
|
|
176
|
+
```powershell
|
|
177
|
+
# 推荐:批量脚本(解析 function list,用内部 id ofn_xxx 调用 PATCH)
|
|
178
|
+
.\项目/<业务名>/本体/ontos/<实现名>/functions/save_test_arguments.ps1
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
单条保存(**须用平台内部 id `ofn_xxx`**,先 `dazi onto function list --space <space-id>` 查看;直接传 `sales.fn.xxx` 可能 **404**):
|
|
182
|
+
|
|
183
|
+
```powershell
|
|
184
|
+
dazi onto function save-test-arguments ofn_156a399fbe0e4636 --space <space-id> `
|
|
185
|
+
--arguments-json-file 项目/<业务名>/本体/ontos/<实现名>/functions/test_arguments/sales.fn.get_summary.json
|
|
107
186
|
```
|
|
108
187
|
|
|
188
|
+
**PowerShell 传 `--params` 易丢引号**;测试运行可省略 `--params`(用 `{}`),或:
|
|
189
|
+
|
|
190
|
+
```powershell
|
|
191
|
+
$env:DAZI_PARAMS='{"start_date":"2025-01-01","end_date":"2026-06-30"}'
|
|
192
|
+
dazi onto function run sales.fn.get_summary --space <space-id> --params $env:DAZI_PARAMS
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
验收:`dazi onto function get <function_id> --space <space-id>` 中 **`test_arguments` 非 null**,且 `arguments` 与 JSON 一致。
|
|
196
|
+
|
|
109
197
|
亦可在 VS Code 侧栏 **Onto 本体 → 发布函数** 发布(须填写/绑定 **function_id**);发布后在 **函数** 节点下应能看到该函数。
|
|
110
198
|
|
|
111
199
|
函数生命周期与 `update-code` 详见 **[本体函数开发指南](./function-guide.md)**。给 TRAE 的完整命令模板见内置提示词 **`onto/script-publish-run`**(`dazi prompt sync` 后位于 `资源/prompts/onto/`)。
|
|
@@ -115,12 +203,16 @@ dazi onto function run sales.fn.get_summary --space <space-id>
|
|
|
115
203
|
若需将平台上已有脚本拉回本地对照(**非**日常开发主路径):
|
|
116
204
|
|
|
117
205
|
```powershell
|
|
206
|
+
# 推荐:落盘到本体实现目录(按 setup / functions 分子目录)
|
|
207
|
+
dazi onto script sync --space <space-id> --target-dir 项目/<业务名>/本体/ontos/<实现名>
|
|
208
|
+
dazi onto script sync --space <space-id> --type ontology_function --target-dir 项目/<业务名>/本体/ontos/<实现名>
|
|
209
|
+
dazi onto script sync --space <space-id> --dry-run --target-dir 项目/<业务名>/本体/ontos/<实现名>
|
|
210
|
+
|
|
211
|
+
# legacy:onto/<space-id>/scripts/(非日常开发入口)
|
|
118
212
|
dazi onto script sync --space <space-id>
|
|
119
|
-
dazi onto script sync --space <space-id> --type ontology_function
|
|
120
|
-
dazi onto script sync --space <space-id> --dry-run
|
|
121
213
|
```
|
|
122
214
|
|
|
123
|
-
拉取目标目录以 CLI 为准;**新建与修改仍以
|
|
215
|
+
拉取目标目录以 CLI 为准;**新建与修改仍以 `项目/<业务名>/本体/ontos/<实现名>/setup/` 与 `functions/` 为准**。
|
|
124
216
|
|
|
125
217
|
## 清理重复脚本
|
|
126
218
|
|
|
@@ -131,10 +223,21 @@ dazi onto script dedupe --space <space-id> --yes
|
|
|
131
223
|
|
|
132
224
|
## 编写建议
|
|
133
225
|
|
|
134
|
-
1. 先阅读
|
|
135
|
-
2. 在
|
|
136
|
-
3.
|
|
137
|
-
4.
|
|
226
|
+
1. 先阅读 `快速启动_<实现名>.md` 与 `README.md` 中的**数据空间 ID**,并对照 `plans/` 中**表间关系**与**函数 test_arguments** 章节
|
|
227
|
+
2. 在 `setup/`、`functions/` 中按模块拆分 `.py`(初始化、灌数、本体函数可分机文件)
|
|
228
|
+
3. **init 脚本**必须包含 `s.tables.add_relationship`(若规划有表间关系)
|
|
229
|
+
4. 发布与运行:`dazi onto script publish`(**函数必须** `--register-function-id`)→ `function run` 验证 → **`save-test-arguments`**
|
|
230
|
+
5. 本地仅调试 Python 语法时可在 VS Code 中直接运行 `.py`(**不会**自动连平台;连平台须发布后在侧栏或 CLI 执行)
|
|
231
|
+
|
|
232
|
+
## 实施自检(智能体 / 人工)
|
|
233
|
+
|
|
234
|
+
| 检查项 | 命令 / 位置 |
|
|
235
|
+
| ------ | ----------- |
|
|
236
|
+
| 表已注册 | 侧栏 **数据资源** 或 `dazi onto space get` → `table_count` |
|
|
237
|
+
| **表间关系已注册** | `relationship_count` > 0;侧栏 **表间关系** |
|
|
238
|
+
| 函数已注册 | `dazi onto function list --space <space-id>` |
|
|
239
|
+
| **test_arguments 已保存** | `dazi onto function get <function_id>` → `test_arguments.arguments` |
|
|
240
|
+
| 函数可运行 | `dazi onto function run <function_id> --space <space-id> --params '{}'` |
|
|
138
241
|
|
|
139
242
|
## 相关文档
|
|
140
243
|
|
|
@@ -142,4 +245,5 @@ dazi onto script dedupe --space <space-id> --yes
|
|
|
142
245
|
- [本体规划指南](./本体规划指南.md)
|
|
143
246
|
- [本体函数开发指南](./function-guide.md)
|
|
144
247
|
- [本体动作开发](./action-guide.md)
|
|
145
|
-
- [
|
|
248
|
+
- [规划示例:产品销售本体(推荐)](./规划示例_产品销售本体规划方案.md)
|
|
249
|
+
- [规划示例:利润分析本体(补充)](./规划示例_利润分析本体方案.md)
|
package/dist/docs/onto//346/234/254/344/275/223/350/247/204/345/210/222/346/214/207/345/215/227.md
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## 目标
|
|
4
4
|
|
|
5
|
-
在
|
|
5
|
+
在 `plans/` 目录中完成本体实现单元的概念设计,包括:
|
|
6
6
|
|
|
7
7
|
- 业务域与边界
|
|
8
8
|
- 对象类型(Object Type)与关键属性
|
|
9
|
-
-
|
|
9
|
+
- **物理表间关系**(事实表 → 维表的 JOIN / FK 语义)
|
|
10
|
+
- 链接类型(Link Type)与基数(**业务对象层**,与表间关系分层写清)
|
|
10
11
|
- 动作(Action)与规则(Rule)的初步清单
|
|
12
|
+
- 本体函数清单及 **test_arguments**(默认测试入参)约定
|
|
11
13
|
|
|
12
14
|
## 本体、Cube 与物理表:三者关系与「业务世界」方法
|
|
13
15
|
|
|
@@ -25,22 +27,46 @@
|
|
|
25
27
|
- 接受 **多对一**:多表、多 Cube 可收敛为一种业务对象;一宽表也可拆成多种业务对象。
|
|
26
28
|
- **链接**两端必须是对象类型 **`code`**,不是 Cube 名;表中仅有 `xxx_id` 时,规划文中仍应写清本体链接语义。
|
|
27
29
|
|
|
30
|
+
### 物理表间关系 vs 本体链接(强制分层)
|
|
31
|
+
|
|
32
|
+
| 维度 | **物理表间关系** | **本体链接(Link Type)** |
|
|
33
|
+
| ---- | ---------------- | ------------------------- |
|
|
34
|
+
| 所在层 | 数据空间 / ClickHouse | 本体 Ontology |
|
|
35
|
+
| 规划章节 | 物理层设计 → **「表间关系」**(建议 §3.x) | 本体层设计 → **「链接类型」** |
|
|
36
|
+
| 侧栏可见 | **数据资源 → 数据空间 → 表间关系** | **Onto 本体 → 链接** |
|
|
37
|
+
| 实施 API | `s.tables.add_relationship(...)`(init 脚本,**表 register 之后**) | `s.onto.define_link_type(...)` |
|
|
38
|
+
| 典型形态 | 事实表 `many_to_one` 维表(`product_id` → `product_master`) | `SalesOrder` → `Product`(订单包含产品) |
|
|
39
|
+
|
|
40
|
+
**常见遗漏**:只写本体 `define_link_type`,init 脚本未调用 `add_relationship` → 空间 **`relationship_count` 为 0**,流程多表 JOIN、AI 读空间上下文时缺少关系元数据。
|
|
41
|
+
|
|
42
|
+
**规划文档必含「表间关系」小节**,至少列清:
|
|
43
|
+
|
|
44
|
+
| 列 | 说明 |
|
|
45
|
+
| -- | ---- |
|
|
46
|
+
| 从表 / 到表 | 物理表名,通常 **从事实表到维表** |
|
|
47
|
+
| 关系类型 | 如 `many_to_one` |
|
|
48
|
+
| join_keys | 如 `product_id → product_id` |
|
|
49
|
+
| join_sql | 如 `sales_order_fact.product_id = product_master.product_id` |
|
|
50
|
+
| 对应本体链接 | 可选对照表,便于评审 |
|
|
51
|
+
|
|
28
52
|
**与业界对象中心实践的对照**:上述分层与「对象优先、数据为 backing」的思路,可与 **Palantir Foundry Ontology**(对象类型、链接、Action、Function 分层)等成熟产品对照阅读;落地脚本时以平台当前 API 与 **`dazi onto`** 能力为准,**不**假设已实现对方全部特性。
|
|
29
53
|
|
|
30
54
|
## 必读文档
|
|
31
55
|
|
|
32
|
-
1.
|
|
33
|
-
2.
|
|
56
|
+
1. **本体规划示例(推荐)**:[`规划示例_产品销售本体规划方案.md`](./规划示例_产品销售本体规划方案.md) — 含表间关系、test_arguments 与完整脚本对照(`dazi docs sync` 后位于 `资源/docs/onto/`)
|
|
57
|
+
2. **补充示例**:[`规划示例_利润分析本体方案.md`](./规划示例_利润分析本体方案.md) — 利润分析域参考
|
|
58
|
+
3. **工作区与 CLI**:`guides/workspace-v3.md`、`guides/cli-reference.md`(`dazi docs sync` 后位于 `资源/docs/guides/`)
|
|
59
|
+
4. **可运行脚本示例**:`资源/examples/onto/销售示例/`(推荐)、`资源/examples/onto/利润示例/`(`dazi examples sync` 或侧栏 **帮助 → 示例**)
|
|
34
60
|
|
|
35
61
|
## 产出约定
|
|
36
62
|
|
|
37
|
-
- **本体方案(规划文档)**:新建/修改的 Markdown **必须**落在
|
|
63
|
+
- **本体方案(规划文档)**:新建/修改的 Markdown **必须**落在 **`项目/<业务名>/本体/ontos/<实现名>/plans/<规划主题>.md`**(这是规划阶段的真产出;**不是**改 `本体规划指南.md`)。
|
|
38
64
|
- 进入脚本实现阶段:遵循 **`本体脚本编写指南.md`**(含发布)、**`function-guide.md`**。
|
|
39
65
|
|
|
40
66
|
## 空间约束(强制)
|
|
41
67
|
|
|
42
|
-
-
|
|
43
|
-
- 若 README 中无 `space_id
|
|
68
|
+
- 本体实现单元创建时已绑定 **数据空间**;`space_id` 以 **`项目/<业务名>/本体/ontos/<实现名>/README.md`** 为准。
|
|
69
|
+
- 若 README 中无 `space_id`(非扩展「新建本体实现」创建),不得新建规划文件,须先让用户补全空间或重新创建实现单元。
|
|
44
70
|
|
|
45
71
|
## LLM 执行指引(必须遵循)
|
|
46
72
|
|
|
@@ -50,22 +76,27 @@
|
|
|
50
76
|
|
|
51
77
|
- **工作区根**:VS Code 已打开的文件夹;多根工作区时在设置 **`dazi.workspaceRoot`** 指定。
|
|
52
78
|
- **平台与登录**:`dazi.serverUrl`;`dazi auth login` 或 `dazi auth set-token`(Token 存 `.dazi/auth.json`)。
|
|
53
|
-
-
|
|
79
|
+
- **业务项目与本体实现单元**(扩展「新建本体实现」时已选定数据空间,**无需**再建 `onto/<space_id>/` 等平行目录):
|
|
54
80
|
|
|
55
81
|
```text
|
|
56
82
|
<工作区根>/
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
83
|
+
项目/<业务名>/ ← 业务项目根
|
|
84
|
+
本体/ ← 本体根目录
|
|
85
|
+
ontos/<实现名>/ ← 本体实现单元(工作单元)
|
|
86
|
+
README.md ← 数据空间 ID、实现元信息(规划/实施均以此为准)
|
|
87
|
+
快速启动_<实现名>.md
|
|
88
|
+
plans/ ← 规划阶段 Markdown 产出
|
|
89
|
+
setup/ ← 初始化 / 灌数脚本
|
|
90
|
+
functions/ ← 本体函数 / 动作脚本
|
|
91
|
+
test_arguments/ ← 各 function_id 的 test_arguments JSON(与 .py 内 TEST_ARGUMENTS 同步)
|
|
92
|
+
资源/docs/onto/ ← 本体指南与规划示例(dazi docs sync)
|
|
93
|
+
资源/dataspaces/ ← 侧栏下载的表结构 Markdown
|
|
63
94
|
```
|
|
64
95
|
|
|
65
96
|
### 规划开始前
|
|
66
97
|
|
|
67
|
-
1. 从
|
|
68
|
-
2. 未绑定 `space_id` 时 **不得** 新建规划 Markdown
|
|
98
|
+
1. 从 **`项目/<业务名>/本体/ontos/<实现名>/README.md`** 读取 **数据空间 ID**(可与设置 `dazi.spaceId` 对照,以 README 为准)。
|
|
99
|
+
2. 未绑定 `space_id` 时 **不得** 新建规划 Markdown,须先让用户通过扩展创建本体实现单元或明确空间。
|
|
69
100
|
|
|
70
101
|
### 规划阶段最小流程
|
|
71
102
|
|
|
@@ -77,7 +108,7 @@ dazi auth whoami
|
|
|
77
108
|
dazi docs sync # 可选:同步帮助文档到 资源/docs/
|
|
78
109
|
```
|
|
79
110
|
|
|
80
|
-
**核对数据空间与现网资产**(`<space_id>`
|
|
111
|
+
**核对数据空间与现网资产**(`<space_id>` 取自当前实现单元的 `README.md`,勿另猜目录):
|
|
81
112
|
|
|
82
113
|
```bash
|
|
83
114
|
dazi onto space list
|
|
@@ -86,32 +117,40 @@ dazi onto space get <space_id> # 可选:查看空间详情
|
|
|
86
117
|
|
|
87
118
|
**扩展侧栏(规划阶段主要入口)**:
|
|
88
119
|
|
|
89
|
-
| 目的 | 操作
|
|
90
|
-
| ------------- |
|
|
91
|
-
| 确认绑定空间 | 打开
|
|
92
|
-
| 查看表 / Cube | **数据资源** → 对应数据空间 → 展开表、Cube
|
|
93
|
-
| 下载表结构 | 表节点右键「下载表信息」→ `资源/dataspaces/`
|
|
94
|
-
| 同步帮助文档 | **帮助** → 下载文档(`dazi docs sync`)
|
|
120
|
+
| 目的 | 操作 |
|
|
121
|
+
| ------------- | ------------------------------------------------------------------------------------- |
|
|
122
|
+
| 确认绑定空间 | 打开 **`项目/<业务名>/本体/ontos/<实现名>/README.md`** 中的数据空间 ID |
|
|
123
|
+
| 查看表 / Cube | **数据资源** → 对应数据空间 → 展开表、Cube |
|
|
124
|
+
| 下载表结构 | 表节点右键「下载表信息」→ `资源/dataspaces/` |
|
|
125
|
+
| 同步帮助文档 | **帮助** → 下载文档(`dazi docs sync`) |
|
|
95
126
|
|
|
96
127
|
> 规划阶段**不**要求本地 `snapshot.json`、`editorial/` 或 `onto/<space_id>/` 目录;以侧栏 **数据资源** 与项目内文档为准即可。
|
|
97
128
|
|
|
98
|
-
规划阶段 **只产出 Markdown**:写入
|
|
129
|
+
规划阶段 **只产出 Markdown**:写入 **`项目/<业务名>/本体/ontos/<实现名>/plans/<主题>.md`**,**首选参考** [`规划示例_产品销售本体规划方案.md`](./规划示例_产品销售本体规划方案.md)。此阶段不发布脚本。
|
|
99
130
|
|
|
100
131
|
### 进入脚本实施
|
|
101
132
|
|
|
102
|
-
脚本写在
|
|
133
|
+
脚本写在 **`项目/<业务名>/本体/ontos/<实现名>/setup/`**(初始化、灌数)与 **`functions/`**(本体函数、动作;Python,见 `dazi.onto.defaultScriptLang`)。发布与运行见 **`本体脚本编写指南.md`**、**`function-guide.md`**:
|
|
103
134
|
|
|
104
135
|
```bash
|
|
105
|
-
dazi onto script publish-preview
|
|
106
|
-
dazi onto script publish
|
|
136
|
+
dazi onto script publish-preview 项目/<业务名>/本体/ontos/<实现名>/functions/my_func.py --space <space_id>
|
|
137
|
+
dazi onto script publish 项目/<业务名>/本体/ontos/<实现名>/functions/my_func.py \
|
|
107
138
|
--space <space_id> \
|
|
108
139
|
--register-function-id <function_id>
|
|
109
140
|
dazi onto function run <function_id> --space <space_id> --params '{}'
|
|
141
|
+
# 函数测试通过后,保存 test_arguments(侧栏「运行函数」预填参数,见本体脚本编写指南)
|
|
110
142
|
```
|
|
111
143
|
|
|
112
|
-
亦可在侧栏 **Onto 本体** 使用「发布函数」「运行函数」等命令(与终端 CLI **同源** bundled;`--space`
|
|
144
|
+
亦可在侧栏 **Onto 本体** 使用「发布函数」「运行函数」等命令(与终端 CLI **同源** bundled;`--space` 与实现单元 README 中的 `space_id` 一致)。
|
|
145
|
+
|
|
146
|
+
**实施顺序(强制)**:
|
|
147
|
+
|
|
148
|
+
1. `setup/*_ontology_init.py`:建表 → `tables.register` → **`tables.add_relationship`** → Cube → 本体对象/链接
|
|
149
|
+
2. `setup/*_seed_data.py`:灌数(幂等)
|
|
150
|
+
3. `functions/*.py`:发布并 **`--register-function-id`**
|
|
151
|
+
4. 运行函数验证 → **`save-test-arguments`** 写入各函数定义的 `test_arguments`
|
|
113
152
|
|
|
114
|
-
实施前可用 `dazi onto function list --space <space_id>`
|
|
153
|
+
实施前可用 `dazi onto function list --space <space_id>` 核对平台已有函数定义;`dazi onto space get <space_id>` 核对 **`relationship_count`** 是否与规划一致。
|
|
115
154
|
|
|
116
155
|
### 失败处理
|
|
117
156
|
|
|
@@ -121,11 +160,14 @@ dazi onto function run <function_id> --space <space_id> --params '{}'
|
|
|
121
160
|
## 自检
|
|
122
161
|
|
|
123
162
|
- 是否写清对象类型、链接、函数/Action、规则(如适用)
|
|
163
|
+
- **物理表间关系**:是否单独成章(从表/到表、join_keys、join_sql、关系类型);是否与 init 脚本步骤对应
|
|
124
164
|
- **`define_link_type` 与对象类型 code**:链接两端须为**已规划且将先创建**的对象类型 **`code`**(与 `define_object_type` 一致);**勿**将 **Cube 名** 或表名当作对象类型 `code`。勿混用仅中文名而无稳定 `code`。
|
|
125
|
-
-
|
|
165
|
+
- **函数 test_arguments**:每个 `function_id` 是否在规划中列出默认参数;是否与 `functions/test_arguments/<function_id>.json` 一致
|
|
166
|
+
- 是否给出实施步骤、风险与验收(含 **relationship_count**、**test_arguments 非 null**)
|
|
126
167
|
|
|
127
168
|
## 相关文档
|
|
128
169
|
|
|
129
170
|
- [本体脚本编写指南](./本体脚本编写指南.md)
|
|
130
171
|
- [本体规划指南](./本体规划指南.md)
|
|
131
|
-
- [
|
|
172
|
+
- [规划示例:产品销售本体(推荐)](./规划示例_产品销售本体规划方案.md)
|
|
173
|
+
- [规划示例:利润分析本体(补充)](./规划示例_利润分析本体方案.md)
|