GitHub user dosubot[bot] added a comment to 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).*
---
<sup>How did I do?
[Good](https://app.dosu.dev/response-feedback/31208ad1-542b-4676-9862-c119d240aa0e?feedback_type=great_response)
|
[Irrelevant](https://app.dosu.dev/response-feedback/31208ad1-542b-4676-9862-c119d240aa0e?feedback_type=irrelevant_answer)
|
[Incorrect](https://app.dosu.dev/response-feedback/31208ad1-542b-4676-9862-c119d240aa0e?feedback_type=incorrect_sources)
|
[Verbose](https://app.dosu.dev/response-feedback/31208ad1-542b-4676-9862-c119d240aa0e?feedback_type=too_verbose)
|
[Hallucination](https://app.dosu.dev/response-feedback/31208ad1-542b-4676-9862-c119d240aa0e?feedback_type=hallucination)
| [Report
🐛](https://app.dosu.dev/response-feedback/31208ad1-542b-4676-9862-c119d240aa0e?feedback_type=bug_report)
|
[Other](https://app.dosu.dev/response-feedback/31208ad1-542b-4676-9862-c119d240aa0e?feedback_type=other)</sup>
[](https://app.dosu.dev/e5e246fa-a522-4d8a-ab3c-e2588b5b501b/ask?utm_source=github) [](https://cursor.com/link/prompt?text=%E4%BD%A0%E7%9A%84%E9%85%8D%E7%BD%AE%E8%BF%98%E6%9C%89%E4%B8%A4%E4%B8%AA%E5%85%B3%E9%94%AE%E7%82%B9%E9%9C%80%E8%A6%81%E4%BF%AE%E6%AD%A3%EF%BC%8C%E5%90%A6%E5%88%99%E8%BE%B9%E4%BC%9A%E5%85%A8%E9%83%A8%E6%8F%92%E5%85%A5%E5%A4%B1%E8%B4%A5%EF%BC%9A%0A%0A1.%20%2A%2Aedge_connected_to.csv%20%E7%9A%84%20id%20%E5%AD%97%E6%AE%B5%E4%B8%8D%E8%A6%81%E5%AF%BC%E5%85%A5%E4%B8%BA%E8%BE%B9%E5%B1%9E%E6%80%A7%2A%2A%20%20%0AHugeGraph%20%E8%BE%B9%E7%9A%84%E5%B1%9E%E6%80%A7%E5%BF%85%E9%A1%BB%E5%9C%A8%20schema.groovy%20%E7%9A%84%20edgeLabel%20%E9%87%8C%E7%94%A8%20.properties%28%29%20%E6%98%8E%E7%A1%AE%E5%A3%B0%E6%98%8E%EF%BC%8C%E5%90%A6%E5%88%99%20loader%20%E4%BC%9A%E6%8A%A5%20%E2%80%9CInvalid%20property%20%27id%27%20for%20edge%20label%E2%80%9D%20%E9%94%99%E8%AF%AF%E3%80%82%E
5%A6%82%E6%9E%9C%E4%BD%A0%E4%B8%8D%E9%9C%80%E8%A6%81%E6%8A%8A%20id%20%E4%BD%9C%E4%B8%BA%E8%BE%B9%E7%9A%84%E5%B1%9E%E6%80%A7%E5%AD%98%E5%82%A8%EF%BC%88%E7%BB%9D%E5%A4%A7%E5%A4%9A%E6%95%B0%E5%9C%BA%E6%99%AF%E9%83%BD%E4%B8%8D%E9%9C%80%E8%A6%81%EF%BC%89%EF%BC%8Cstruct.json%20%E7%9A%84%20field_mapping%20%E5%8F%AA%E5%86%99%20from/to%EF%BC%8C%E4%B8%8D%E8%A6%81%E5%86%99%20id%E3%80%82%E6%AF%94%E5%A6%82%EF%BC%9A%0A%0A%60%60%60json%0A%22field_mapping%22%3A%20%7B%20%22from%22%3A%20%22id%22%2C%20%22to%22%3A%20%22id%22%20%7D%0A%60%60%60%0AedgeLabel%20%E7%9A%84%20.properties%28%29%20%E5%8F%AA%E5%86%99%20%22source_label%22%2C%20%22target_label%22%EF%BC%88%E5%A6%82%E6%9E%9C%E4%BD%A0%E9%9C%80%E8%A6%81%E5%AD%98%E5%82%A8%20source_label/target_label%EF%BC%89%EF%BC%8C%E4%B8%8D%E8%A6%81%E5%8A%A0%20%22id%22%E3%80%82%0A%0A2.%20%2A%2Avalue_mapping%20%E5%BF%85%E9%A1%BB%E6%98%AF%E5%B9%B3%E9%93%BA%E7%BB%93%E6%9E%84%EF%BC%8C%E4%B8%8D%E8%83%BD%E5%B5%8C%E5%A5%97%2A%2A%20%20%0A%E6%AD%A3%E7%A1%AE%E5%86%99%E6%B3%95%E
6%98%AF%EF%BC%9A%0A%0A%60%60%60json%0A%22value_mapping%22%3A%20%7B%0A%20%20%22label%22%3A%20%7B%20%22CONNECTED_TO%22%3A%20%22LineSegment2LineSegment%22%20%7D%2C%0A%20%20%22source_label%22%3A%20%7B%20%22LineSegment%22%3A%20%22LineSegment%22%20%7D%2C%0A%20%20%22target_label%22%3A%20%7B%20%22LineSegment%22%3A%20%22LineSegment%22%20%7D%0A%7D%0A%60%60%60%0A%E4%B8%8D%E8%A6%81%E5%86%99%E6%88%90%E5%B5%8C%E5%A5%97%E5%9C%A8%20label%20%E4%B8%8B%E9%9D%A2%E7%9A%84%E7%BB%93%E6%9E%84%E3%80%82%0A%0A---%0A%0A%2A%2A%E6%A0%87%E5%87%86%E5%86%99%E6%B3%95%E4%B8%BE%E4%BE%8B%EF%BC%9A%2A%2A%0A%0Aschema.groovy%EF%BC%88%E4%BB%A5%20LineSegment2LineSegment%20%E4%B8%BA%E4%BE%8B%EF%BC%89%EF%BC%9A%0A%60%60%60groovy%0Aschema.edgeLabel%28%22LineSegment2LineSegment%22%29%0A%20%20%20%20.sourceLabel%28%22LineSegment%22%29%0A%20%20%20%20.targetLabel%28%22LineSegment%22%29%0A%20%20%20%20.properties%28%22source_label%22%2C%20%22target_label%22%29%0A%20%20%20%20.ifNotExist%28%29.create%28%29%3B%0A%60%60%60%0A%0Astruct.json
%EF%BC%88%E4%BB%A5%20LineSegment2LineSegment%20%E4%B8%BA%E4%BE%8B%EF%BC%89%EF%BC%9A%0A%60%60%60json%0A%7B%0A%20%20%22label%22%3A%20%22LineSegment2LineSegment%22%2C%0A%20%20%22source%22%3A%20%5B%22from%22%5D%2C%0A%20%20%22target%22%3A%20%5B%22to%22%5D%2C%0A%20%20%22input%22%3A%20%7B%0A%20%20%20%20%22type%22%3A%20%22file%22%2C%0A%20%20%20%20%22path%22%3A%20%22/loader/power_data/edge_connected_to.csv%22%2C%0A%20%20%20%20%22format%22%3A%20%22CSV%22%2C%0A%20%20%20%20%22header%22%3A%20%5B%22id%22%2C%20%22from%22%2C%20%22to%22%2C%20%22label%22%2C%20%22source_label%22%2C%20%22target_label%22%5D%0A%20%20%7D%2C%0A%20%20%22field_mapping%22%3A%20%7B%20%22from%22%3A%20%22id%22%2C%20%22to%22%3A%20%22id%22%20%7D%2C%0A%20%20%22value_mapping%22%3A%20%7B%0A%20%20%20%20%22label%22%3A%20%7B%20%22CONNECTED_TO%22%3A%20%22LineSegment2LineSegment%22%20%7D%2C%0A%20%20%20%20%22source_label%22%3A%20%7B%20%22LineSegment%22%3A%20%22LineSegment%22%20%7D%2C%0A%20%20%20%20%22target_label%22%3A%20%7B%20%22LineSegme
nt%22%3A%20%22LineSegment%22%20%7D%0A%20%20%7D%0A%7D%0A%60%60%60%0A%0A---%0A%0A%2A%2A%E6%A3%80%E6%9F%A5%E6%B8%85%E5%8D%95%EF%BC%9A%2A%2A%0A-%20edgeLabel%20%E7%9A%84%20.properties%28%29%20%E5%8F%AA%E5%8C%85%E5%90%AB%E5%AE%9E%E9%99%85%E9%9C%80%E8%A6%81%E7%9A%84%E5%B1%9E%E6%80%A7%EF%BC%88%E5%A6%82%20%22source_label%22%2C%20%22target_label%22%EF%BC%89%EF%BC%8C%E4%B8%8D%E8%A6%81%E5%8A%A0%20%22id%22%E3%80%82%0A-%20struct.json%20%E7%9A%84%20field_mapping%20%E5%8F%AA%E5%86%99%20from/to%EF%BC%8C%E4%B8%8D%E8%A6%81%E5%86%99%20id%E3%80%82%0A-%20value_mapping%20%E5%BF%85%E9%A1%BB%E6%98%AF%E5%B9%B3%E9%93%BA%E7%BB%93%E6%9E%84%E3%80%82%0A-%20edge_connected_to.csv%20%E7%9A%84%20source_label/target_label%20%E5%BF%85%E9%A1%BB%E5%92%8C%E9%A1%B6%E7%82%B9%20label%20%E5%AE%8C%E5%85%A8%E4%B8%80%E8%87%B4%EF%BC%88%E5%8C%BA%E5%88%86%E5%A4%A7%E5%B0%8F%E5%86%99%EF%BC%89%E3%80%82%0A%0A%E8%BF%99%E6%A0%B7%E9%85%8D%E7%BD%AE%E5%90%8E%EF%BC%8C%E8%BE%B9%E5%B0%B1%E8%83%BD%E6%AD%A3%E5%B8%B8%E5%AF%BC%E5%85%A5%E4%B8%94%E6
%97%A0%E6%8A%A5%E9%94%99%E3%80%82%E5%A6%82%E6%9E%9C%E8%BF%98%E6%9C%89%E5%85%B7%E4%BD%93%E6%8A%A5%E9%94%99%EF%BC%8C%E5%8F%AF%E4%BB%A5%E8%B4%B4%E5%87%BA%20struct.json/schema.groovy/CSV%20%E7%9A%84%E7%89%87%E6%AE%B5%EF%BC%8C%E6%88%91%E5%8F%AF%E4%BB%A5%E5%B8%AE%E4%BD%A0%E9%80%90%E6%9D%A1%E6%A3%80%E6%9F%A5%E3%80%82%20%20%0A%E8%AF%A6%E7%BB%86%E6%9C%BA%E5%88%B6%E8%A7%81%5B%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%5D%28https%3A//github.com/apache/incubator-hugegraph-doc/blob/3e1c610281c91ea3a5c600b393088e9ffae34799/content/en/docs/quickstart/toolchain/hugegraph-loader.md%23L705-L1064%29%E3%80%82) [](https://go.dosu.dev/discord-bot) [](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/incubator-hugegraph/discussions/2917)
GitHub link:
https://github.com/apache/incubator-hugegraph/discussions/2917#discussioncomment-15205241
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]