GitHub user dosubot[bot] edited a comment on the discussion: 关于电网拓扑数据导入
<!-- Answer -->
你的配置现在只差一个关键点就能导入成功,但你还遗漏了最核心的地方:
**你的 struct.json 里所有 edges 的 field_mapping 必须写成:**
```json
"field_mapping": { "from": "from", "to": "to" }
```
而且 **不能写成** `{ "from": "id", "to": "id" }` 或 `{ "from": "id", "to": "id", ...
}`,否则 loader 会把 CSV 的 id 列当作边属性导入,但 schema.groovy 的 edgeLabel 没有声明 id 属性,导致
“Invalid property 'id' for edge label” 或 “主键字段 [id] 为空”
的报错。[官方文档说明](https://github.com/apache/incubator-hugegraph-doc/blob/master/content/en/docs/quickstart/toolchain/hugegraph-loader.md#L705-L1064)
**你现在遇到的 “Make sure the primary key fields [id] are not empty, or check whether
the headers or field_mapping are configured correctly” 报错,根本原因是:**
- 你的顶点主键是 id(vertex_xxx.csv 里有 id 列,schema 里 primaryKeys("id")),loader 只会用
from/to 字段的值直接作为顶点主键 id,不会再去查 vertex_xxx.csv 的其他字段。
- edge_connected_to.csv 的 id 列可以保留,但 loader 不会导入它为边属性,只要 field_mapping 不写 id
就不会报错。
- edgeLabel 的 .properties() 只包含 "source_label", "target_label",不要加 "id"。
- value_mapping 必须是平铺结构(你现在的写法没问题)。
- null_values 建议只保留 ["NULL", "null"],不要加 "",否则空字符串会被判定为 null。
**请你务必检查:**
1. struct.json 里所有 edges 的 field_mapping 都是 `"field_mapping": { "from": "from",
"to": "to" }`,没有任何 id。
2. edge_connected_to.csv 的 from/to 字段和所有顶点 id 完全一致(无多余空格、无大小写问题、无空行)。
3. struct.json 的 null_values 只保留 ["NULL", "null"],不要加 ""。
4. edgeLabel 的 .properties() 只包含 "source_label", "target_label",不要加 "id"。
5. 你可以加 `"selected": ["from", "to"]` 显式指定用到的字段,避免 loader 解析其它无关列。
**如果还有报错,请贴出 power_edges_to.csv 的 header 和前几行原始数据,以及 struct.json 某个 edges
配置的完整内容,我可以帮你定位具体是哪一行或哪一列有问题。**
只要这几点全部做到,边就能正常导入且无报错,所有关系都能导入。[官方FAQ说明](https://github.com/apache/incubator-hugegraph-doc/blob/master/content/en/docs/guides/faq.md)
<!-- 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).*
---
Share context across your team and agents. Try
[Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-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=knowledge-infrastructure-feedback&utm_term=apache%2Fhugegraph#message_id=17a00ddc-43bf-46d2-a63a-11c737a46136)
[](https://github.dosu.com/apache/hugegraph?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-learn-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=knowledge-infrastructure-add-team&utm_term=apache%2Fhugegraph)
GitHub link:
https://github.com/apache/hugegraph/discussions/2917#discussioncomment-15216084
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]