GitHub user dosubot[bot] edited a comment on the discussion: 关于电网拓扑数据导入
<!-- Answer --> 你的配置有两个关键问题导致边全部插入失败: 1. **edge_connected_to.csv 的 id 字段被当作边属性导入,但 schema.groovy 的边标签没有定义 id 属性** HugeGraph 边的属性必须在 schema.groovy 的 edgeLabel 里用 .properties() 明确声明,否则 loader 会报 “Invalid property 'id' for edge label” 错误([官方文档说明](https://github.com/apache/incubator-hugegraph-doc/blob/3e1c610281c91ea3a5c600b393088e9ffae34799/content/en/docs/quickstart/toolchain/hugegraph-loader.md#L705-L1064))。 你现在 edge_connected_to.csv 有 id 字段,struct.json 的 field_mapping 也把 from/to 映射为 id,但 edgeLabel 没有 .properties("id"),所以全部失败。 **修正方法:** - 如果你不需要把 id 作为边的属性存储(大多数场景都不需要),直接把 struct.json 里 edges 的 field_mapping 改成只映射 from/to,不要映射 id 字段。比如: ```json "field_mapping": { "from": "id", "to": "id" } ``` 并且 edgeLabel 的 .properties() 里不要加 "id"。 - 如果你确实需要把 id 作为边属性存储(极少数场景),那就要在 schema.groovy 的每个 edgeLabel 里加上 .properties("id", "source_label", "target_label"),并且 propertyKey 也要定义 id。 2. **struct.json 的 value_mapping 要是平铺结构,不能嵌套在 label 下面** 正确写法是: ```json "value_mapping": { "label": { "CONNECTED_TO": "LineSegment2LineSegment" }, "source_label": { "LineSegment": "LineSegment" }, "target_label": { "LineSegment": "LineSegment" } } ``` 不要写成 ```json "value_mapping": { "label": { "CONNECTED_TO": "LineSegment2LineSegment", "source_label": { ... }, "target_label": { ... } } } ``` **建议你这样修改:** - schema.groovy 的每个 edgeLabel 只写 .properties("source_label", "target_label"),不要加 "id"。 - struct.json 的 field_mapping 只写 from/to,不要写 id。 - edge_connected_to.csv 的 id 字段可以保留,但 loader 不会导入它为边属性。 - value_mapping 写成平铺结构。 **举例:** 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() 里没定义 id,field_mapping 就不能把 id 当作边属性导入,否则必报错。 - 只要 source_label/target_label 和顶点 label 完全一致,value_mapping 写法正确,所有关系都能导入。 如还有问题,可以贴出具体的 struct.json 某一段和 schema.groovy 某一段,我可以帮你逐条检查。 详细机制见[官方文档](https://github.com/apache/incubator-hugegraph-doc/blob/3e1c610281c91ea3a5c600b393088e9ffae34799/content/en/docs/quickstart/toolchain/hugegraph-loader.md#L705-L1064)。 <!-- 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).* --- Docs are dead. Just use [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-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=static-docs-feedback&utm_term=apache%2Fhugegraph#message_id=71c5bf25-8374-4df9-8a6a-06ad067afd8b) [](https://github.dosu.com/apache/hugegraph?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-ask-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=static-docs-share-team&utm_term=apache%2Fhugegraph) GitHub link: https://github.com/apache/hugegraph/discussions/2917#discussioncomment-15205066 ---- This is an automatically sent email for [email protected]. To unsubscribe, please send an email to: [email protected]
