@dazitech/cli 3.0.9 → 3.1.0
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 +1 -1
- package/dist/clis/dazi-onto.js +7 -2
- package/dist/clis/dazi.js +1 -1
- package/dist/docs/flow/flow-project-guide.md +1 -1
- package/dist/docs/guides/troubleshooting.md +3 -3
- package/dist/docs/index.json +3 -3
- package/dist/docs/onto/dazi_script_sdk_reference.md +246 -244
- package/dist/docs/onto/function-guide.md +123 -123
- 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 +24 -23
- 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 -402
- package/dist/docs/onto//346/234/254/344/275/223/345/274/200/345/217/221/344/274/230/345/214/226/346/200/273/347/273/223.md +242 -0
- 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 +339 -311
- package/dist/docs/onto//346/234/254/344/275/223/350/247/204/345/210/222/346/214/207/345/215/227.md +304 -281
- package/dist/docs/onto//350/204/232/346/234/254/350/277/220/350/241/214/345/270/270/350/247/201/351/224/231/350/257/257/345/244/204/347/220/206.md +242 -0
- 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 +32 -32
- 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 +34 -32
- package/dist/examples/index.json +1 -1
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_category_mount.py +85 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_ontology_init.py +2 -65
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_category_mount.py +82 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_ontology_init.py +2 -53
- package/dist/prompts/index.json +8 -1
- package/dist/prompts/onto/function-design.md +73 -73
- package/dist/prompts/onto/planning-design.md +104 -0
- package/dist/prompts/onto/script-publish-run.md +229 -208
- package/package.json +1 -1
- 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 +0 -213
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
# 脚本运行纠错 · 商务成本方案开发过程记录
|
|
2
|
-
|
|
3
|
-
**文档 ID**: `onto/script-run-troubleshooting`
|
|
4
|
-
**级别**: **执行脚本前必读(强制)** — 在终端执行 `dazi onto script publish` / `script run` / `function run` / `save-test-arguments` **之前**须通读
|
|
5
|
-
**场景**: 本体 init / seed / 函数发布与运行过程中的 API 误用、SQL 聚合、CLI 参数等真实踩坑记录(潘达石化 · 商务成本本体方案)
|
|
6
|
-
**适用**: 编写 `setup/`、`functions/` 脚本及终端发布验证时对照;智能体见提示词 `onto/script-publish-run`
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
## 一、遇到的坑
|
|
11
|
-
|
|
12
|
-
### 1. setup 脚本 API 误用(多次尝试才正确)
|
|
13
|
-
|
|
14
|
-
| 错误写法 | 正确写法 | 说明 |
|
|
15
|
-
| --------------------------------------------- | --------------------------------------------------------------------------- | ---------------------------- |
|
|
16
|
-
| `s.onto.sync_metrics()` | 删除,平台自动同步 | `sync_metrics` 方法不存在 |
|
|
17
|
-
| `s.cubes.upsert(...)` | `s.register_cube(...)` | `cubes` 属性不存在 |
|
|
18
|
-
| `s.onto.define_object_type(code, label=name)` | `s.onto.define_object_type(code, name, description=desc)` | 参数名为 `name` 而非 `label` |
|
|
19
|
-
| `define_link_type(..., from_object_type=...)` | `define_link_type(..., from_object_type_code=..., to_object_type_code=...)` | 参数名以 `_code` 结尾 |
|
|
20
|
-
|
|
21
|
-
**教训**:参考利润示例脚本的 API 用法,不要猜测方法名。
|
|
22
|
-
|
|
23
|
-
### 2. 函数聚合查询返回类型错误
|
|
24
|
-
|
|
25
|
-
**问题代码**:
|
|
26
|
-
|
|
27
|
-
```python
|
|
28
|
-
total_row = p.sql.query_one(f"SELECT sum(amount) AS grand_total FROM ...")
|
|
29
|
-
grand_total = float(total_row.get("grand_total", 0)) # float 无 .get()
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
**原因**:`p.sql.query_one()` 对聚合查询返回的是数值(float),而非包含字段名的字典行。
|
|
33
|
-
|
|
34
|
-
**修复**:
|
|
35
|
-
|
|
36
|
-
```python
|
|
37
|
-
total_rows = p.sql.query(f"SELECT sum(amount) AS grand_total FROM ...")
|
|
38
|
-
total_row = total_rows[0] if total_rows else {}
|
|
39
|
-
grand_total = float(total_row.get("grand_total", 0) or 0)
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
受影响的函数:
|
|
43
|
-
|
|
44
|
-
- `cost_fn_category_breakdown.py`
|
|
45
|
-
- `cost_fn_department_breakdown.py`
|
|
46
|
-
- `cost_fn_top_cost_types.py`
|
|
47
|
-
|
|
48
|
-
### 3. 函数输出方式错误(`output.print_json`)
|
|
49
|
-
|
|
50
|
-
**问题代码**:
|
|
51
|
-
|
|
52
|
-
```python
|
|
53
|
-
def main():
|
|
54
|
-
result = _ontology_fn_body(p)
|
|
55
|
-
output.print_json(result) # AttributeError: 'OutputModule' has no attribute 'print_json'
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
**原因**:本体函数运行时平台注入 `ctx`、`space`、`onto` 等;**结果须由 `main()` return**,不能调用 `output.print_json()`(setup/flow 脚本中的 `output` 模块与本体函数不同)。
|
|
59
|
-
|
|
60
|
-
**正确写法**(与销售/利润示例一致):
|
|
61
|
-
|
|
62
|
-
```python
|
|
63
|
-
def _ontology_fn_body(p):
|
|
64
|
-
params = dict(p.get_params() or {})
|
|
65
|
-
# ... SQL via p.sql.query(...)
|
|
66
|
-
return p.function_result(
|
|
67
|
-
columns=["col_a", "col_b"],
|
|
68
|
-
data=[{"col_a": 1, "col_b": 2}],
|
|
69
|
-
row_count=1,
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
def main():
|
|
74
|
-
s = space.get(ctx.space_id or "")
|
|
75
|
-
_Ports = type(
|
|
76
|
-
"_Ports",
|
|
77
|
-
(),
|
|
78
|
-
{
|
|
79
|
-
"get_params": lambda self: dict(ctx.params or {}),
|
|
80
|
-
"function_result": lambda self, **kw: onto.function_result(**kw),
|
|
81
|
-
},
|
|
82
|
-
)
|
|
83
|
-
p = _Ports()
|
|
84
|
-
p.sql = s.sql
|
|
85
|
-
return _ontology_fn_body(p)
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
**禁止**:`output.print_json`、`print()` 作为最终输出、仅 `return {"key": val}` 裸 dict(应使用 `onto.function_result` / `p.function_result`)。
|
|
89
|
-
|
|
90
|
-
**模板**:`资源/examples/onto/_templates/ontology_function_template.py`(`dazi examples show onto/template/ontology-function`)。完整说明见 [function-guide · 函数脚本结构](./function-guide.md#函数脚本结构标准模板)。
|
|
91
|
-
|
|
92
|
-
### 4. CLI 参数认知错误
|
|
93
|
-
|
|
94
|
-
#### 坑 A:`function run` 不支持 `--arguments-json-file`
|
|
95
|
-
|
|
96
|
-
```powershell
|
|
97
|
-
# 错误 — 提示 unknown option
|
|
98
|
-
dazi onto function run cost.fn.get_summary --space space__ljzeng --arguments-json-file "xxx.json"
|
|
99
|
-
|
|
100
|
-
# 正确 — 先 save-test-arguments 保存默认参数,run 时不传文件
|
|
101
|
-
dazi onto function run cost.fn.get_summary --space space__ljzeng
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
#### 坑 B:`save-test-arguments` 用错 ID 类型
|
|
105
|
-
|
|
106
|
-
```powershell
|
|
107
|
-
# 错误 — 用了 function_id(平台不认)
|
|
108
|
-
dazi onto function save-test-arguments cost.fn.get_summary --space space__ljzeng ...
|
|
109
|
-
|
|
110
|
-
# 正确 — 用 ofn_ 开头的内部注册 ID
|
|
111
|
-
dazi onto function save-test-arguments ofn_97a01c967ed24b03 --space space__ljzeng ...
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
**获取方法**:`dazi onto function list --space space__ljzeng`,返回 JSON 中的 `id` 字段即为 ofn_xxx。
|
|
115
|
-
|
|
116
|
-
---
|
|
117
|
-
|
|
118
|
-
## 二、正确 CLI 操作清单
|
|
119
|
-
|
|
120
|
-
前提:在 `dazi-work` 根目录执行,所有路径相对于根目录。
|
|
121
|
-
|
|
122
|
-
### 1. 发布初始化脚本(setup 类型)
|
|
123
|
-
|
|
124
|
-
```powershell
|
|
125
|
-
dazi onto script publish 项目/潘达石化/本体/ontos/商务成本本体方案/setup/cost_ontology_init.py --space space__ljzeng --type setup
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
### 2. 执行初始化脚本
|
|
129
|
-
|
|
130
|
-
```powershell
|
|
131
|
-
dazi onto script run --file 项目/潘达石化/本体/ontos/商务成本本体方案/setup/cost_ontology_init.py --space space__ljzeng
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
### 3. 发布灌数脚本(data 类型)
|
|
135
|
-
|
|
136
|
-
```powershell
|
|
137
|
-
dazi onto script publish 项目/潘达石化/本体/ontos/商务成本本体方案/setup/cost_seed_data.py --space space__ljzeng --type data
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
### 4. 执行灌数脚本
|
|
141
|
-
|
|
142
|
-
```powershell
|
|
143
|
-
dazi onto script run --file 项目/潘达石化/本体/ontos/商务成本本体方案/setup/cost_seed_data.py --space space__ljzeng
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
### 5. 发布本体函数(必须带 `--register-function-id`)
|
|
147
|
-
|
|
148
|
-
```powershell
|
|
149
|
-
# 每个函数单独发布
|
|
150
|
-
dazi onto script publish 项目/潘达石化/本体/ontos/商务成本本体方案/functions/cost_fn_get_summary.py --space space__ljzeng --register-function-id cost.fn.get_summary
|
|
151
|
-
dazi onto script publish 项目/潘达石化/本体/ontos/商务成本本体方案/functions/cost_fn_category_breakdown.py --space space__ljzeng --register-function-id cost.fn.category_breakdown
|
|
152
|
-
dazi onto script publish 项目/潘达石化/本体/ontos/商务成本本体方案/functions/cost_fn_department_breakdown.py --space space__ljzeng --register-function-id cost.fn.department_breakdown
|
|
153
|
-
dazi onto script publish 项目/潘达石化/本体/ontos/商务成本本体方案/functions/cost_fn_top_cost_types.py --space space__ljzeng --register-function-id cost.fn.top_cost_types
|
|
154
|
-
dazi onto script publish 项目/潘达石化/本体/ontos/商务成本本体方案/functions/cost_fn_budget_vs_actual.py --space space__ljzeng --register-function-id cost.fn.budget_vs_actual
|
|
155
|
-
dazi onto script publish 项目/潘达石化/本体/ontos/商务成本本体方案/functions/cost_fn_mom_analysis.py --space space__ljzeng --register-function-id cost.fn.mom_analysis
|
|
156
|
-
dazi onto script publish 项目/潘达石化/本体/ontos/商务成本本体方案/functions/cost_fn_yoy_analysis.py --space space__ljzeng --register-function-id cost.fn.yoy_analysis
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
### 6. 查询函数内部 ID(用于保存默认参数)
|
|
160
|
-
|
|
161
|
-
```powershell
|
|
162
|
-
dazi onto function list --space space__ljzeng
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
从 JSON 输出中提取每个函数的 `id`(格式为 `ofn_xxx`)。
|
|
166
|
-
|
|
167
|
-
### 7. 保存默认测试参数(test_arguments)
|
|
168
|
-
|
|
169
|
-
```powershell
|
|
170
|
-
# 先查 list 获取 ofn_xxx,再逐个保存
|
|
171
|
-
dazi onto function save-test-arguments <ofn_internal_id> --space space__ljzeng --arguments-json-file 项目/潘达石化/本体/ontos/商务成本本体方案/functions/test_arguments/<function_id>.json
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
### 8. 运行函数验证
|
|
175
|
-
|
|
176
|
-
```powershell
|
|
177
|
-
dazi onto function run <function_id> --space space__ljzeng
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
**注意**:运行时不传 `--arguments-json-file`,参数来自第 7 步预存的 test_arguments。
|
|
181
|
-
|
|
182
|
-
---
|
|
183
|
-
|
|
184
|
-
## 三、修改函数代码后的正确流程
|
|
185
|
-
|
|
186
|
-
如果函数代码有 bug 修复,重复以下步骤:
|
|
187
|
-
|
|
188
|
-
1. **重新发布**(版本号自动 +1)
|
|
189
|
-
2. **运行验证**:`dazi onto function run <function_id> --space space__ljzeng`
|
|
190
|
-
3. **重新保存 test_arguments**(如果参数有变化)
|
|
191
|
-
|
|
192
|
-
---
|
|
193
|
-
|
|
194
|
-
## 四、关键 CLI 命令速查
|
|
195
|
-
|
|
196
|
-
| 目的 | 命令 |
|
|
197
|
-
| ------------------- | ---------------------------------------------------------------------------------------------- |
|
|
198
|
-
| 发布 setup 脚本 | `dazi onto script publish <path> --space <space> --type setup` |
|
|
199
|
-
| 发布 data 脚本 | `dazi onto script publish <path> --space <space> --type data` |
|
|
200
|
-
| 发布函数(注册 ID) | `dazi onto script publish <path> --space <space> --register-function-id <fn.id>` |
|
|
201
|
-
| 执行脚本 | `dazi onto script run --file <path> --space <space>` |
|
|
202
|
-
| 运行函数 | `dazi onto function run <function_id> --space <space>` |
|
|
203
|
-
| 查询函数列表+ID | `dazi onto function list --space <space>` |
|
|
204
|
-
| 保存默认参数 | `dazi onto function save-test-arguments <ofn_id> --space <space> --arguments-json-file <json>` |
|
|
205
|
-
|
|
206
|
-
## 五、相关文档
|
|
207
|
-
|
|
208
|
-
| 文档 | 说明 |
|
|
209
|
-
| ---- | ---- |
|
|
210
|
-
| [本体脚本编写指南](./本体脚本编写指南.md) | 目录约定、发布顺序、test_arguments |
|
|
211
|
-
| [本体函数开发指南](./function-guide.md) | 函数生命周期、**标准 main 模板**、`save-test-arguments` |
|
|
212
|
-
| [DaziScript SDK 参考](./dazi_script_sdk_reference.md) | `s.sql` / `s.onto` / Cube API |
|
|
213
|
-
| [故障排查](../guides/troubleshooting.md) | CLI 环境、401、侧栏空白等 |
|