GitHub user dosubot[bot] edited a comment on the discussion: 关于电网拓扑数据导入
<!-- Answer -->
你的配置只差一步就能导入成功:**每个边标签(edgeLabel)的 .properties() 必须包含所有实际要导入的属性**,否则 loader 会报
“Invalid property 'source_label' for edge label” 这样的错【参考1】【参考2】。
你现在 schema.groovy 里边标签是这样写的:
```groovy
schema.edgeLabel("Substation2LineSegment").sourceLabel("Substation").targetLabel("LineSegment").properties().ifNotExist().create();
```
应该改成:
```groovy
schema.edgeLabel("Substation2LineSegment")
.sourceLabel("Substation")
.targetLabel("LineSegment")
.properties("source_label", "target_label")
.ifNotExist().create();
```
所有用到 source_label、target_label 的边标签都要这样写(不要加 id,除非你真的要把 id 作为边属性存储)。你的
struct.json 和 value_mapping 写法是对的,field_mapping 只写 from/to 就行。
**标准写法举例:**
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 完全一致(区分大小写)。
这样配置后,边就能正常导入且无报错,所有关系都能导入【参考3】【参考4】。
如还有具体报错,可以贴出 struct.json/schema.groovy/CSV 的片段,我可以帮你逐条检查。
---
**参考:**
-
[官方文档:边属性声明与导入机制](https://github.com/apache/incubator-hugegraph-doc/blob/master/content/en/docs/quickstart/toolchain/hugegraph-loader.md#L705-L1064)
-
[源码机制说明](https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/schema/builder/EdgeLabelBuilder.java)
- [官方 schema
示例](https://github.com/apache/incubator-hugegraph-doc/blob/master/content/en/docs/language/hugegraph-example.md)
- [社区案例](https://github.com/apache/incubator-hugegraph/issues/2749)
<!-- 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=fa4343d7-2c63-4f02-90bb-c6af0b0fac2c)
[](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-15205750
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]