GitHub user dosubot[bot] edited a comment on the discussion: 关于电网拓扑数据导入
<!-- Answer -->
你的配置还有两个关键点需要修正,否则边会全部插入失败:
1. **edge_connected_to.csv 的 id 字段不要导入为边属性**
HugeGraph 边的属性必须在 schema.groovy 的 edgeLabel 里用 .properties() 明确声明,否则 loader 会报
“Invalid property 'id' for edge label” 错误。如果你不需要把 id
作为边的属性存储(绝大多数场景都不需要),struct.json 的 field_mapping 只写 from/to,不要写 id。比如:
```json
"field_mapping": { "from": "id", "to": "id" }
```
edgeLabel 的 .properties() 只写 "source_label", "target_label"(如果你需要存储
source_label/target_label),不要加 "id"。
2. **value_mapping 必须是平铺结构,不能嵌套**
正确写法是:
```json
"value_mapping": {
"label": { "CONNECTED_TO": "LineSegment2LineSegment" },
"source_label": { "LineSegment": "LineSegment" },
"target_label": { "LineSegment": "LineSegment" }
}
```
不要写成嵌套在 label 下面的结构。
---
**标准写法举例:**
schema.groovy(以 LineSegment2LineSegment 为例):
```groovy
schema.edgeLabel("LineSegment2LineSegment")
.sourceLabel("LineSegment")
.targetLabel("LineSegment")
.properties("source_label", "target_label")
.ifNotExist().create();
```
struct.json(以 LineSegment2LineSegment 为例):
```json
{
"label": "LineSegment2LineSegment",
"source": ["from"],
"target": ["to"],
"input": {
"type": "file",
"path": "/loader/power_data/edge_connected_to.csv",
"format": "CSV",
"header": ["id", "from", "to", "label", "source_label", "target_label"]
},
"field_mapping": { "from": "id", "to": "id" },
"value_mapping": {
"label": { "CONNECTED_TO": "LineSegment2LineSegment" },
"source_label": { "LineSegment": "LineSegment" },
"target_label": { "LineSegment": "LineSegment" }
}
}
```
---
**检查清单:**
- edgeLabel 的 .properties() 只包含实际需要的属性(如 "source_label", "target_label"),不要加
"id"。
- struct.json 的 field_mapping 只写 from/to,不要写 id。
- value_mapping 必须是平铺结构。
- edge_connected_to.csv 的 source_label/target_label 必须和顶点 label 完全一致(区分大小写)。
这样配置后,边就能正常导入且无报错。如果还有具体报错,可以贴出 struct.json/schema.groovy/CSV 的片段,我可以帮你逐条检查。
详细机制见[官方文档](https://github.com/apache/incubator-hugegraph-doc/blob/3e1c610281c91ea3a5c600b393088e9ffae34799/content/en/docs/quickstart/toolchain/hugegraph-loader.md#L705-L1064)。
<!-- 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=31208ad1-542b-4676-9862-c119d240aa0e)
[](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-15205241
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]