GitHub user dosubot[bot] edited a comment on the discussion: 关于电网拓扑数据导入
<!-- Answer -->
我是 AI 助手,每条回复都会结合你贴出的最新代码和报错逐行分析。
你现在遇到的 “Make sure the primary key fields [id] are not empty, or check whether
the headers or field_mapping are configured correctly” 报错,根本原因是 struct.json 的
field_mapping 配置和顶点主键字段不匹配。
**你的配置问题:**
你的顶点主键是 id(vertex_xxx.csv 里有 id 列,schema 里 primaryKeys("id")),但你 struct.json 的
edges 里 field_mapping 写成了:
```json
"field_mapping": { "from": "from", "to": "to" }
```
这会导致 loader 用 edge_connected_to.csv 的 from/to 字段去查找顶点的主键字段(id),**但 loader 只会把
from/to 的值直接作为顶点主键 id**,不会再去查 vertex_xxx.csv 的其他字段。
**最常见的坑:**
- edge_connected_to.csv 的 from/to 字段有空值、拼写错误、隐藏字符,或者和顶点 id
不完全一致(比如有多余空格、大小写不一致),都会导致 loader 解析不到主键,报这个错。
- struct.json 的 null_values 配置如果包含 "" 或 "null",而 edge_connected_to.csv 某些
from/to 字段正好是空字符串或 "null",也会被判定为空。
- edge_connected_to.csv 的 header 必须严格为
id,from,to,label,source_label,target_label,不能有多余空格或 BOM。
**排查 checklist:**
1. 检查 edge_connected_to.csv 的 from/to 列,确保所有值都和顶点 CSV 的 id
完全一致(无多余空格、无大小写问题、无空行)。
2. 检查 struct.json 的 field_mapping,必须是:
```json
"field_mapping": { "from": "from", "to": "to" }
```
不要有 id。
3. 检查 struct.json 的 null_values,建议只保留 ["NULL", "null"],不要加 "",否则空字符串会被判定为 null。
4. 检查 edge_connected_to.csv 的 header 行,确保没有 BOM、没有多余空格,且顺序和 struct.json 里
header 完全一致。
5. 检查所有边的 from/to 字段都不为空。
6. 检查 struct.json 里所有 edges 配置都同步修改了 field_mapping,没有遗漏。
**你可以用文本编辑器或 Excel 检查 edge_connected_to.csv 的 from/to 列,确保没有空值或格式问题。**
如果还有问题,请贴出 edge_connected_to.csv 的 header 和前几行原始数据(不要做任何处理),以及 struct.json 里某个
edges 配置的完整内容,我可以帮你定位具体是哪一行或哪一列有问题。
我会一直结合你最新贴出的内容逐条分析,不会遗漏细节。如需进一步定位,可以贴出 loader 的详细报错堆栈和数据样例。
<!-- Dosu Comment Footer -->
*To reply, just mention
[@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fhugegraph).*
---
Docs are dead. Just use
[Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-tagline&utm_term=apache%2Fhugegraph).
[](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-feedback&utm_term=apache%2Fhugegraph#message_id=c90b6f11-089c-4eb7-90af-0e57f5c269c9)
[](https://github.dosu.com/apache/hugegraph?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-ask-repo&utm_term=apache%2Fhugegraph)
[](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-share-team&utm_term=apache%2Fhugegraph)
GitHub link:
https://github.com/apache/hugegraph/discussions/2917#discussioncomment-15206306
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]