GitHub user dosubot[bot] edited a comment on 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?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=9b6ffcbb-d6c3-48d7-ab43-1e38ee0cc630) [](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-15204078 ---- This is an automatically sent email for [email protected]. To unsubscribe, please send an email to: [email protected]
