GitHub user dosubot[bot] added a comment to 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).*

---
<sup>How did I do? 
[Good](https://app.dosu.dev/response-feedback/fa4343d7-2c63-4f02-90bb-c6af0b0fac2c?feedback_type=great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/fa4343d7-2c63-4f02-90bb-c6af0b0fac2c?feedback_type=irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/fa4343d7-2c63-4f02-90bb-c6af0b0fac2c?feedback_type=incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/fa4343d7-2c63-4f02-90bb-c6af0b0fac2c?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/fa4343d7-2c63-4f02-90bb-c6af0b0fac2c?feedback_type=hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/fa4343d7-2c63-4f02-90bb-c6af0b0fac2c?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/fa4343d7-2c63-4f02-90bb-c6af0b0fac2c?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%E7%9A%84%E9%85%8D%E7%BD%AE%E5%8F%AA%E5%B7%AE%E4%B8%80%E6%AD%A5%E5%B0%B1%E8%83%BD%E5%AF%BC%E5%85%A5%E6%88%90%E5%8A%9F%EF%BC%9A%2A%2A%E6%AF%8F%E4%B8%AA%E8%BE%B9%E6%A0%87%E7%AD%BE%EF%BC%88edgeLabel%EF%BC%89%E7%9A%84%20.properties%28%29%20%E5%BF%85%E9%A1%BB%E5%8C%85%E5%90%AB%E6%89%80%E6%9C%89%E5%AE%9E%E9%99%85%E8%A6%81%E5%AF%BC%E5%85%A5%E7%9A%84%E5%B1%9E%E6%80%A7%2A%2A%EF%BC%8C%E5%90%A6%E5%88%99%20loader%20%E4%BC%9A%E6%8A%A5%20%E2%80%9CInvalid%20property%20%27source_label%27%20for%20edge%20label%E2%80%9D%20%E8%BF%99%E6%A0%B7%E7%9A%84%E9%94%99%E3%80%90%E5%8F%82%E8%80%831%E3%80%91%E3%80%90%E5%8F%82%E8%80%832%E3%80%91%E3%80%82%0A%0A%E4%BD%A0%E7%8E%B0%E5%9C%A8%20schema.groovy%20%E9%87%8C%E8%BE%B9%E6%A0%87%E7%AD%BE%E6%98%AF%E8%BF%99%E6%A0%B7%E5%86%99
 
%E7%9A%84%EF%BC%9A%0A%0A%60%60%60groovy%0Aschema.edgeLabel%28%22Substation2LineSegment%22%29.sourceLabel%28%22Substation%22%29.targetLabel%28%22LineSegment%22%29.properties%28%29.ifNotExist%28%29.create%28%29%3B%0A%60%60%60%0A%0A%E5%BA%94%E8%AF%A5%E6%94%B9%E6%88%90%EF%BC%9A%0A%0A%60%60%60groovy%0Aschema.edgeLabel%28%22Substation2LineSegment%22%29%0A%20%20%20%20.sourceLabel%28%22Substation%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%0A%E6%89%80%E6%9C%89%E7%94%A8%E5%88%B0%20source_label%E3%80%81target_label%20%E7%9A%84%E8%BE%B9%E6%A0%87%E7%AD%BE%E9%83%BD%E8%A6%81%E8%BF%99%E6%A0%B7%E5%86%99%EF%BC%88%E4%B8%8D%E8%A6%81%E5%8A%A0%20id%EF%BC%8C%E9%99%A4%E9%9D%9E%E4%BD%A0%E7%9C%9F%E7%9A%84%E8%A6%81%E6%8A%8A%20id%20%E4%BD%9C%E4%B8%BA%E8%BE%B9%E5%B1%9E%E6%80%A7%E5%AD%98%E5%82%A8%EF%BC%89%E3%80%82%E4%BD%A0%E7%9A%84%20struct.json%20%E5%92%8C%20value
 
_mapping%20%E5%86%99%E6%B3%95%E6%98%AF%E5%AF%B9%E7%9A%84%EF%BC%8Cfield_mapping%20%E5%8F%AA%E5%86%99%20from/to%20%E5%B0%B1%E8%A1%8C%E3%80%82%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%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%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%22pa
 
th%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%22LineSegment%22%3A%20%22LineSegment%22%20%7D%0A%20%20%7D%0A%7D%0A%60%60%60%0A%0A%2A%2A%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9%EF%BC%9A%2A%2A%0A-%20edgeLabel%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%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%EF%BC%8C%E6%89%80%E6%9C%89%E5%85%B3%E7%B3%BB%E9%83%BD%E8%83%BD%E5%AF%BC%E5%85%A5%E3%80%90%E5%8F%82%E8%80%833%E3%80%91%E3%80%90%E5%8F%82%E8%80%834%E3%80%91%E3%80%82%0A%0A%E5%A6%82%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%0A%0A---%0A%2A%2A%E5%8F%82%E8%80%83%EF%BC%9A%2A%2A%0A-%20%5B%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%EF%BC%9A%E8%BE%B9%E5%B1%9E%E6%80%A7%E5%A3%B0%E6%98%8E%E4%B8%8E%E5%AF%BC%E5%85%A5%E6%9C%BA%E5%88%B6%5D%28https%3A//github.com/apache/incubator-hugegraph-doc/blob/master/content/en/docs/quickstart/toolchain/hugegraph-loader.md%23L705-L1064%29%0A-%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/blob/master/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/schema/builder/EdgeLabelBuilder.java%29%0A-%20%5B%E5%AE%98%E6%96%B9%20schema%20%E7%A4%BA%E4%BE%8B%5D%28https%3A//github.com/apache/incubator-hugegraph-doc/blob/master/content/en/docs/language/hugegraph-example.md%29%0A-%20%5B%E7%A4%BE%E5%8C%BA%E6%A1%88%E4%BE%8B%5D%28https%3A//github.com/apache/incubator-hugegraph/issues/2749%29)&nbsp;[![Join
 
Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/d
 iscord-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-15205750

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

Reply via email to