GitHub user dosubot[bot] added a comment to the discussion: 关于电网拓扑数据导入

<!-- Answer -->
你导入成功但连接关系不全,最常见的原因是 struct.json 里的 edges 
配置没有把所有类型的边(比如变电站-线路、线路-站房、线路-开关等)都正确映射到 schema.groovy 里定义的 edgeLabel。HugeGraph 
的边标签(edgeLabel)只能连接一种源点和目标点类型,且必须和顶点的 label 完全匹配,否则边会被跳过但不会报错,loader 
只统计“插入成功”但实际没有建立你想要的关系 
[源码机制说明](https://github.com/apache/incubator-hugegraph-toolchain/blob/9696d78e4d0b6e10d4e3382248fd8bda61295a91/hugegraph-loader/src/main/java/org/apache/hugegraph/loader/builder/EdgeBuilder.java#L43-L264)。

你现在 struct.json 只定义了 CONNECTED_TO 这一个 edgeLabel,且 source/target 都是 id,实际只会导入 
Substation-Substation 这种关系,其他类型(比如 
Substation-LineSegment、LineSegment-StationHouse、LineSegment-LineSwitch 
等)都不会导入成功。

**解决办法:**
1. schema.groovy 里每种类型关系都要有一个 edgeLabel,比如 
Substation2LineSegment、LineSegment2StationHouse、LineSegment2LineSegment、LineSegment2LineSwitch、LineSwitch2LineSegment
 等。
2. struct.json 里 edges 部分要为每个 edgeLabel 配置一段,source/target 字段要和顶点主键字段一致(比如 
["from"], ["to"]),并用 value_mapping 或 selected 过滤出当前 edgeLabel 需要的边类型。
3. edge_connected_to.csv 只要有 from、to、label 字段即可,所有边都放一起没问题,struct.json 里用 
value_mapping 匹配不同 edgeLabel。

**举例:**
```json
{
  "label": "Substation2LineSegment",
  "source": ["from"],
  "target": ["to"],
  "input": { "type": "file", "path": 
"/loader/power_data/edge_connected_to.csv", "format": "CSV", "header": ["id", 
"from", "to", "label"] },
  "field_mapping": { "from": "id", "to": "id" },
  "value_mapping": { "label": { "CONNECTED_TO": "Substation2LineSegment" } }
},
{
  "label": "LineSegment2StationHouse",
  "source": ["from"],
  "target": ["to"],
  "input": { ... },
  "field_mapping": { ... },
  "value_mapping": { "label": { "CONNECTED_TO": "LineSegment2StationHouse" } }
}
```
每种类型的边都要写一段,path 都可以指向同一个 edge_connected_to.csv。

**注意:**
- 顶点的 label 必须和 schema 里的 vertexLabel 一致,比如 LineSegment、StationHouse、LineSwitch 
等。
- edgeLabel 的 sourceLabel/targetLabel 必须和顶点 label 一一对应。
- 如果边是双向的,数据里要有正反两条记录(A→B 和 B→A),edgeLabel 只需定义一次。

**参考案例和详细配置说明:**
- 
[官方文档](https://github.com/apache/incubator-hugegraph-doc/blob/master/content/cn/docs/quickstart/toolchain/hugegraph-loader.md)
- [社区类似问题与解决方法](https://github.com/apache/incubator-hugegraph/issues/2749)

如果你愿意,可以把 struct_1.json 和 schema_1.groovy 贴出来,我可以帮你逐条检查。


<!-- 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/9b6ffcbb-d6c3-48d7-ab43-1e38ee0cc630?feedback_type=great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/9b6ffcbb-d6c3-48d7-ab43-1e38ee0cc630?feedback_type=irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/9b6ffcbb-d6c3-48d7-ab43-1e38ee0cc630?feedback_type=incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/9b6ffcbb-d6c3-48d7-ab43-1e38ee0cc630?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/9b6ffcbb-d6c3-48d7-ab43-1e38ee0cc630?feedback_type=hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/9b6ffcbb-d6c3-48d7-ab43-1e38ee0cc630?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/9b6ffcbb-d6c3-48d7-ab43-1e38ee0cc630?feedback_type=other)</sup>

[![Chat with 
Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/e5e246fa-a522-4d8a-ab3c-e2588b5b501b/ask?utm_source=github)&nbsp;[![Open
 in 
Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=%E4%BD%A0%E5%AF%BC%E5%85%A5%E6%88%90%E5%8A%9F%E4%BD%86%E8%BF%9E%E6%8E%A5%E5%85%B3%E7%B3%BB%E4%B8%8D%E5%85%A8%EF%BC%8C%E6%9C%80%E5%B8%B8%E8%A7%81%E7%9A%84%E5%8E%9F%E5%9B%A0%E6%98%AF%20struct.json%20%E9%87%8C%E7%9A%84%20edges%20%E9%85%8D%E7%BD%AE%E6%B2%A1%E6%9C%89%E6%8A%8A%E6%89%80%E6%9C%89%E7%B1%BB%E5%9E%8B%E7%9A%84%E8%BE%B9%EF%BC%88%E6%AF%94%E5%A6%82%E5%8F%98%E7%94%B5%E7%AB%99-%E7%BA%BF%E8%B7%AF%E3%80%81%E7%BA%BF%E8%B7%AF-%E7%AB%99%E6%88%BF%E3%80%81%E7%BA%BF%E8%B7%AF-%E5%BC%80%E5%85%B3%E7%AD%89%EF%BC%89%E9%83%BD%E6%AD%A3%E7%A1%AE%E6%98%A0%E5%B0%84%E5%88%B0%20schema.groovy%20%E9%87%8C%E5%AE%9A%E4%B9%89%E7%9A%84%20edgeLabel%E3%80%82HugeGraph%20%E7%9A%84%E8%BE%B9%E6%A0%87%E7%AD%BE%EF%BC%88edgeLabel%EF%BC%89%E5%8F%AA%E8%83%BD%E8%BF%9E%E6%8E%A5%E4%B8%80%E7
 
%A7%8D%E6%BA%90%E7%82%B9%E5%92%8C%E7%9B%AE%E6%A0%87%E7%82%B9%E7%B1%BB%E5%9E%8B%EF%BC%8C%E4%B8%94%E5%BF%85%E9%A1%BB%E5%92%8C%E9%A1%B6%E7%82%B9%E7%9A%84%20label%20%E5%AE%8C%E5%85%A8%E5%8C%B9%E9%85%8D%EF%BC%8C%E5%90%A6%E5%88%99%E8%BE%B9%E4%BC%9A%E8%A2%AB%E8%B7%B3%E8%BF%87%E4%BD%86%E4%B8%8D%E4%BC%9A%E6%8A%A5%E9%94%99%EF%BC%8Cloader%20%E5%8F%AA%E7%BB%9F%E8%AE%A1%E2%80%9C%E6%8F%92%E5%85%A5%E6%88%90%E5%8A%9F%E2%80%9D%E4%BD%86%E5%AE%9E%E9%99%85%E6%B2%A1%E6%9C%89%E5%BB%BA%E7%AB%8B%E4%BD%A0%E6%83%B3%E8%A6%81%E7%9A%84%E5%85%B3%E7%B3%BB%20%5B%E6%BA%90%E7%A0%81%E6%9C%BA%E5%88%B6%E8%AF%B4%E6%98%8E%5D%28https%3A//github.com/apache/incubator-hugegraph-toolchain/blob/9696d78e4d0b6e10d4e3382248fd8bda61295a91/hugegraph-loader/src/main/java/org/apache/hugegraph/loader/builder/EdgeBuilder.java%23L43-L264%29%E3%80%82%0A%0A%E4%BD%A0%E7%8E%B0%E5%9C%A8%20struct.json%20%E5%8F%AA%E5%AE%9A%E4%B9%89%E4%BA%86%20CONNECTED_TO%20%E8%BF%99%E4%B8%80%E4%B8%AA%20edgeLabel%EF%BC%8C%E4%B8%94%20source/target%20%E9%83%BD%E
 
6%98%AF%20id%EF%BC%8C%E5%AE%9E%E9%99%85%E5%8F%AA%E4%BC%9A%E5%AF%BC%E5%85%A5%20Substation-Substation%20%E8%BF%99%E7%A7%8D%E5%85%B3%E7%B3%BB%EF%BC%8C%E5%85%B6%E4%BB%96%E7%B1%BB%E5%9E%8B%EF%BC%88%E6%AF%94%E5%A6%82%20Substation-LineSegment%E3%80%81LineSegment-StationHouse%E3%80%81LineSegment-LineSwitch%20%E7%AD%89%EF%BC%89%E9%83%BD%E4%B8%8D%E4%BC%9A%E5%AF%BC%E5%85%A5%E6%88%90%E5%8A%9F%E3%80%82%0A%0A%2A%2A%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95%EF%BC%9A%2A%2A%0A1.%20schema.groovy%20%E9%87%8C%E6%AF%8F%E7%A7%8D%E7%B1%BB%E5%9E%8B%E5%85%B3%E7%B3%BB%E9%83%BD%E8%A6%81%E6%9C%89%E4%B8%80%E4%B8%AA%20edgeLabel%EF%BC%8C%E6%AF%94%E5%A6%82%20Substation2LineSegment%E3%80%81LineSegment2StationHouse%E3%80%81LineSegment2LineSegment%E3%80%81LineSegment2LineSwitch%E3%80%81LineSwitch2LineSegment%20%E7%AD%89%E3%80%82%0A2.%20struct.json%20%E9%87%8C%20edges%20%E9%83%A8%E5%88%86%E8%A6%81%E4%B8%BA%E6%AF%8F%E4%B8%AA%20edgeLabel%20%E9%85%8D%E7%BD%AE%E4%B8%80%E6%AE%B5%EF%BC%8Csource/target%20%E5%AD%97%E6%AE%B5%E8%A6%8
 
1%E5%92%8C%E9%A1%B6%E7%82%B9%E4%B8%BB%E9%94%AE%E5%AD%97%E6%AE%B5%E4%B8%80%E8%87%B4%EF%BC%88%E6%AF%94%E5%A6%82%20%5B%22from%22%5D%2C%20%5B%22to%22%5D%EF%BC%89%EF%BC%8C%E5%B9%B6%E7%94%A8%20value_mapping%20%E6%88%96%20selected%20%E8%BF%87%E6%BB%A4%E5%87%BA%E5%BD%93%E5%89%8D%20edgeLabel%20%E9%9C%80%E8%A6%81%E7%9A%84%E8%BE%B9%E7%B1%BB%E5%9E%8B%E3%80%82%0A3.%20edge_connected_to.csv%20%E5%8F%AA%E8%A6%81%E6%9C%89%20from%E3%80%81to%E3%80%81label%20%E5%AD%97%E6%AE%B5%E5%8D%B3%E5%8F%AF%EF%BC%8C%E6%89%80%E6%9C%89%E8%BE%B9%E9%83%BD%E6%94%BE%E4%B8%80%E8%B5%B7%E6%B2%A1%E9%97%AE%E9%A2%98%EF%BC%8Cstruct.json%20%E9%87%8C%E7%94%A8%20value_mapping%20%E5%8C%B9%E9%85%8D%E4%B8%8D%E5%90%8C%20edgeLabel%E3%80%82%0A%0A%2A%2A%E4%B8%BE%E4%BE%8B%EF%BC%9A%2A%2A%0A%60%60%60json%0A%7B%0A%20%20%22label%22%3A%20%22Substation2LineSegment%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%20%22type%22%3A%20%22file%22%2C%20%22path%22%3A%20%22/load
 
er/power_data/edge_connected_to.csv%22%2C%20%22format%22%3A%20%22CSV%22%2C%20%22header%22%3A%20%5B%22id%22%2C%20%22from%22%2C%20%22to%22%2C%20%22label%22%5D%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%20%22label%22%3A%20%7B%20%22CONNECTED_TO%22%3A%20%22Substation2LineSegment%22%20%7D%20%7D%0A%7D%2C%0A%7B%0A%20%20%22label%22%3A%20%22LineSegment2StationHouse%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%20...%20%7D%2C%0A%20%20%22field_mapping%22%3A%20%7B%20...%20%7D%2C%0A%20%20%22value_mapping%22%3A%20%7B%20%22label%22%3A%20%7B%20%22CONNECTED_TO%22%3A%20%22LineSegment2StationHouse%22%20%7D%20%7D%0A%7D%0A%60%60%60%0A%E6%AF%8F%E7%A7%8D%E7%B1%BB%E5%9E%8B%E7%9A%84%E8%BE%B9%E9%83%BD%E8%A6%81%E5%86%99%E4%B8%80%E6%AE%B5%EF%BC%8Cpath%20%E9%83%BD%E5%8F%AF%E4%BB%A5%E6%8C%87%E5%90%91%E5%90%8C%E4%B8%80%E4%B8%AA%20edge
 
_connected_to.csv%E3%80%82%0A%0A%2A%2A%E6%B3%A8%E6%84%8F%EF%BC%9A%2A%2A%0A-%20%E9%A1%B6%E7%82%B9%E7%9A%84%20label%20%E5%BF%85%E9%A1%BB%E5%92%8C%20schema%20%E9%87%8C%E7%9A%84%20vertexLabel%20%E4%B8%80%E8%87%B4%EF%BC%8C%E6%AF%94%E5%A6%82%20LineSegment%E3%80%81StationHouse%E3%80%81LineSwitch%20%E7%AD%89%E3%80%82%0A-%20edgeLabel%20%E7%9A%84%20sourceLabel/targetLabel%20%E5%BF%85%E9%A1%BB%E5%92%8C%E9%A1%B6%E7%82%B9%20label%20%E4%B8%80%E4%B8%80%E5%AF%B9%E5%BA%94%E3%80%82%0A-%20%E5%A6%82%E6%9E%9C%E8%BE%B9%E6%98%AF%E5%8F%8C%E5%90%91%E7%9A%84%EF%BC%8C%E6%95%B0%E6%8D%AE%E9%87%8C%E8%A6%81%E6%9C%89%E6%AD%A3%E5%8F%8D%E4%B8%A4%E6%9D%A1%E8%AE%B0%E5%BD%95%EF%BC%88A%E2%86%92B%20%E5%92%8C%20B%E2%86%92A%EF%BC%89%EF%BC%8CedgeLabel%20%E5%8F%AA%E9%9C%80%E5%AE%9A%E4%B9%89%E4%B8%80%E6%AC%A1%E3%80%82%0A%0A%2A%2A%E5%8F%82%E8%80%83%E6%A1%88%E4%BE%8B%E5%92%8C%E8%AF%A6%E7%BB%86%E9%85%8D%E7%BD%AE%E8%AF%B4%E6%98%8E%EF%BC%9A%2A%2A%0A-%20%5B%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%5D%28https%3A//github.com/apache/incuba
 
tor-hugegraph-doc/blob/master/content/cn/docs/quickstart/toolchain/hugegraph-loader.md%29%0A-%20%5B%E7%A4%BE%E5%8C%BA%E7%B1%BB%E4%BC%BC%E9%97%AE%E9%A2%98%E4%B8%8E%E8%A7%A3%E5%86%B3%E6%96%B9%E6%B3%95%5D%28https%3A//github.com/apache/incubator-hugegraph/issues/2749%29%0A%0A%E5%A6%82%E6%9E%9C%E4%BD%A0%E6%84%BF%E6%84%8F%EF%BC%8C%E5%8F%AF%E4%BB%A5%E6%8A%8A%20struct_1.json%20%E5%92%8C%20schema_1.groovy%20%E8%B4%B4%E5%87%BA%E6%9D%A5%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)&nbsp;[![Join
 
Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share
 on 
X](https://img.shields.io/badge/X-share-black)](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-15204078

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]

Reply via email to