GitHub user dosubot[bot] added a comment to the discussion: 关于电网拓扑数据导入
<!-- Answer -->
你只需要在 schema.groovy 里加上这两行即可解决 “属性键'source_label'不存在” 的报错:
```groovy
schema.propertyKey("source_label").asText().ifNotExist().create();
schema.propertyKey("target_label").asText().ifNotExist().create();
```
建议把这两行放在所有 propertyKey 定义的部分(和 id、name 等属性一起)。这样 loader 才能识别 struct.json 和
edge_connected_to.csv 里的 source_label、target_label 字段。
如果你希望把 source_label 和 target_label 作为边的属性存储(可选),可以在相关 edgeLabel 的 .properties()
里加上这两个属性,比如:
```groovy
schema.edgeLabel("LineSegment2StationHouse")
.sourceLabel("LineSegment")
.targetLabel("StationHouse")
.properties("source_label", "target_label")
.ifNotExist().create();
```
注意事项:
- edge_connected_to.csv 的 source_label/target_label 列内容必须和 schema.groovy 里顶点
label 完全一致(区分大小写),比如 LineSegment、StationHouse、LineSwitch、Substation。
- struct.json 的 value_mapping 要是平铺结构,不要嵌套在 label 下面,应该是:
```json
"value_mapping": {
"label": { "CONNECTED_TO": "LineSegment2StationHouse" },
"source_label": { "LineSegment": "LineSegment" },
"target_label": { "StationHouse": "StationHouse" }
}
```
- 修改 schema 后,重新执行 schema 创建和数据导入流程。
官方文档有详细说明:[schema.propertyKey
定义示例](https://github.com/apache/incubator-hugegraph-doc/blob/3e1c610281c91ea3a5c600b393088e9ffae34799/content/en/docs/quickstart/toolchain/hugegraph-loader.md#L897-L1100)
如还有问题,可以贴出 struct.json、schema.groovy 和 edge_connected_to.csv 的片段,我可以帮你逐条检查。
<!-- 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/8d940d65-8081-4ff5-a3b8-edb36aabc995?feedback_type=great_response)
|
[Irrelevant](https://app.dosu.dev/response-feedback/8d940d65-8081-4ff5-a3b8-edb36aabc995?feedback_type=irrelevant_answer)
|
[Incorrect](https://app.dosu.dev/response-feedback/8d940d65-8081-4ff5-a3b8-edb36aabc995?feedback_type=incorrect_sources)
|
[Verbose](https://app.dosu.dev/response-feedback/8d940d65-8081-4ff5-a3b8-edb36aabc995?feedback_type=too_verbose)
|
[Hallucination](https://app.dosu.dev/response-feedback/8d940d65-8081-4ff5-a3b8-edb36aabc995?feedback_type=hallucination)
| [Report
🐛](https://app.dosu.dev/response-feedback/8d940d65-8081-4ff5-a3b8-edb36aabc995?feedback_type=bug_report)
|
[Other](https://app.dosu.dev/response-feedback/8d940d65-8081-4ff5-a3b8-edb36aabc995?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%E5%8F%AA%E9%9C%80%E8%A6%81%E5%9C%A8%20schema.groovy%20%E9%87%8C%E5%8A%A0%E4%B8%8A%E8%BF%99%E4%B8%A4%E8%A1%8C%E5%8D%B3%E5%8F%AF%E8%A7%A3%E5%86%B3%20%E2%80%9C%E5%B1%9E%E6%80%A7%E9%94%AE%27source_label%27%E4%B8%8D%E5%AD%98%E5%9C%A8%E2%80%9D%20%E7%9A%84%E6%8A%A5%E9%94%99%EF%BC%9A%0A%0A%60%60%60groovy%0Aschema.propertyKey%28%22source_label%22%29.asText%28%29.ifNotExist%28%29.create%28%29%3B%0Aschema.propertyKey%28%22target_label%22%29.asText%28%29.ifNotExist%28%29.create%28%29%3B%0A%60%60%60%0A%0A%E5%BB%BA%E8%AE%AE%E6%8A%8A%E8%BF%99%E4%B8%A4%E8%A1%8C%E6%94%BE%E5%9C%A8%E6%89%80%E6%9C%89%20propertyKey%20%E5%AE%9A%E4%B9%89%E7%9A%84%E9%83%A8%E5%88%86%EF%BC%88%E5%92%8C%20id%E3%80%81name%20%E7%AD%89%E5%B1%9E%E6%80%A7%E4%B8%80%E8%B5%B7%EF%BC%89%E3%80%82
%E8%BF%99%E6%A0%B7%20loader%20%E6%89%8D%E8%83%BD%E8%AF%86%E5%88%AB%20struct.json%20%E5%92%8C%20edge_connected_to.csv%20%E9%87%8C%E7%9A%84%20source_label%E3%80%81target_label%20%E5%AD%97%E6%AE%B5%E3%80%82%0A%0A%E5%A6%82%E6%9E%9C%E4%BD%A0%E5%B8%8C%E6%9C%9B%E6%8A%8A%20source_label%20%E5%92%8C%20target_label%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%E5%8F%AF%E9%80%89%EF%BC%89%EF%BC%8C%E5%8F%AF%E4%BB%A5%E5%9C%A8%E7%9B%B8%E5%85%B3%20edgeLabel%20%E7%9A%84%20.properties%28%29%20%E9%87%8C%E5%8A%A0%E4%B8%8A%E8%BF%99%E4%B8%A4%E4%B8%AA%E5%B1%9E%E6%80%A7%EF%BC%8C%E6%AF%94%E5%A6%82%EF%BC%9A%0A%0A%60%60%60groovy%0Aschema.edgeLabel%28%22LineSegment2StationHouse%22%29%0A%20%20%20%20.sourceLabel%28%22LineSegment%22%29%0A%20%20%20%20.targetLabel%28%22StationHouse%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%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9%EF%BC%9A%0A-%20edg
e_connected_to.csv%20%E7%9A%84%20source_label/target_label%20%E5%88%97%E5%86%85%E5%AE%B9%E5%BF%85%E9%A1%BB%E5%92%8C%20schema.groovy%20%E9%87%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%EF%BC%8C%E6%AF%94%E5%A6%82%20LineSegment%E3%80%81StationHouse%E3%80%81LineSwitch%E3%80%81Substation%E3%80%82%0A-%20struct.json%20%E7%9A%84%20value_mapping%20%E8%A6%81%E6%98%AF%E5%B9%B3%E9%93%BA%E7%BB%93%E6%9E%84%EF%BC%8C%E4%B8%8D%E8%A6%81%E5%B5%8C%E5%A5%97%E5%9C%A8%20label%20%E4%B8%8B%E9%9D%A2%EF%BC%8C%E5%BA%94%E8%AF%A5%E6%98%AF%EF%BC%9A%0A%20%20%60%60%60json%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%22LineSegment2StationHouse%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%22StationHouse%22%3A%20%22StationHouse%22%20%7D%0A%20%20%7D%0A%20%20%60%60%60%0A-%20%E
4%BF%AE%E6%94%B9%20schema%20%E5%90%8E%EF%BC%8C%E9%87%8D%E6%96%B0%E6%89%A7%E8%A1%8C%20schema%20%E5%88%9B%E5%BB%BA%E5%92%8C%E6%95%B0%E6%8D%AE%E5%AF%BC%E5%85%A5%E6%B5%81%E7%A8%8B%E3%80%82%0A%0A%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E6%9C%89%E8%AF%A6%E7%BB%86%E8%AF%B4%E6%98%8E%EF%BC%9A%5Bschema.propertyKey%20%E5%AE%9A%E4%B9%89%E7%A4%BA%E4%BE%8B%5D%28https%3A//github.com/apache/incubator-hugegraph-doc/blob/3e1c610281c91ea3a5c600b393088e9ffae34799/content/en/docs/quickstart/toolchain/hugegraph-loader.md%23L897-L1100%29%0A%0A%E5%A6%82%E8%BF%98%E6%9C%89%E9%97%AE%E9%A2%98%EF%BC%8C%E5%8F%AF%E4%BB%A5%E8%B4%B4%E5%87%BA%20struct.json%E3%80%81schema.groovy%20%E5%92%8C%20edge_connected_to.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) [](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-15204714
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]