GitHub user wangzhewwzz added a comment to the discussion: 关于电网拓扑数据导入

您看这样可以吗 我把我的脚本和数据用附件发您 你可以帮我改好吗  然后我再消化
         原始邮件
         
       
发件人:dosubot[bot] ***@***.***>
发件时间:2025年12月9日 14:31
收件人:apache/incubator-hugegraph ***@***.***>
抄送:wangzhewwzz ***@***.***>, Mention ***@***.***>
主题:Re: [apache/incubator-hugegraph] 关于电网拓扑数据导入 (Discussion #2917)




你的配置有两个关键问题导致边全部插入失败:

edge_connected_to.csv 的 id 字段被当作边属性导入,但 schema.groovy 的边标签没有定义 id 属性
 HugeGraph 边的属性必须在 schema.groovy 的 edgeLabel 里用 .properties() 明确声明,否则 loader 会报 
“Invalid property 'id' for edge label” 错误(官方文档说明)。
 你现在 edge_connected_to.csv 有 id 字段,struct.json 的 field_mapping 也把 from/to 映射为 
id,但 edgeLabel 没有 .properties("id"),所以全部失败。

修正方法:


如果你不需要把 id 作为边的属性存储(大多数场景都不需要),直接把 struct.json 里 edges 的 field_mapping 改成只映射 
from/to,不要映射 id 字段。比如:
"field_mapping": { "from": "id", "to": "id" }

并且 edgeLabel 的 .properties() 里不要加 "id"。



如果你确实需要把 id 作为边属性存储(极少数场景),那就要在 schema.groovy 的每个 edgeLabel 里加上 
.properties("id", "source_label", "target_label"),并且 propertyKey 也要定义 id。


struct.json 的 value_mapping 要是平铺结构,不能嵌套在 label 下面
 正确写法是:
"value_mapping": {   "label": { "CONNECTED_TO": "LineSegment2LineSegment" 
},   "source_label": { "LineSegment": "LineSegment" },  
 "target_label": { "LineSegment": "LineSegment" } }

不要写成
"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 为例):
schema.edgeLabel("LineSegment2LineSegment")    
 .sourceLabel("LineSegment")     .targetLabel("LineSegment")  
   .properties("source_label", "target_label")    
 .ifNotExist().create();

struct.json(以 LineSegment2LineSegment 为例):
{   "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 某一段,我可以帮你逐条检查。
 详细机制见官方文档。

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | 
Hallucination | Report 🐛 | Other

   

—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.

GitHub link: 
https://github.com/apache/incubator-hugegraph/discussions/2917#discussioncomment-15205184

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

Reply via email to