GitHub user wangzhewwzz added a comment to the discussion: 关于电网拓扑数据导入
全部都改成 "field_mapping": { "from": "from", "to": "to" }还是一样报错呀你AI的问题时候 麻烦认真点
power_edges_to.csv :
id,from,to,label,source_label,target_label
edge_1,BDZ-3002,XLD-3445,CONNECTED_TO,Substation,LineSegment
edge_2,XLD-3445,BDZ-3002,CONNECTED_TO,LineSegment,Substation
edge_3,XLD-3445,HWX-3087,CONNECTED_TO,LineSegment,StationHouse
edge_4,HWX-3087,XLD-3445,CONNECTED_TO,StationHouse,LineSegment
edge_5,HWX-3087,XLD-3258,CONNECTED_TO,StationHouse,LineSegment
edge_6,HWX-3087,XLD-3455,CONNECTED_TO,StationHouse,LineSegment
edge_7,XLD-3258,HWX-3087,CONNECTED_TO,LineSegment,StationHouse
edge_8,XLD-3258,HWX-3109,CONNECTED_TO,LineSegment,StationHouse
edge_9,XLD-3455,HWX-3087,CONNECTED_TO,LineSegment,StationHouse
edge_10,XLD-3455,XLKG-3019,CONNECTED_TO,LineSegment,LineSwitch
edge_11,HWX-3109,XLD-3258,CONNECTED_TO,StationHouse,LineSegment
edge_12,HWX-3109,XLD-3673,CONNECTED_TO,StationHouse,LineSegment
edge_13,HWX-3109,XLD-3699,CONNECTED_TO,StationHouse,LineSegment
edge_14,HWX-3109,XLD-3505,CONNECTED_TO,StationHouse,LineSegment
edge_15,XLKG-3019,XLD-3455,CONNECTED_TO,LineSwitch,LineSegment
edge_16,XLKG-3019,XLD-3724,CONNECTED_TO,LineSwitch,LineSegment
edge_17,XLD-3673,HWX-3109,CONNECTED_TO,LineSegment,StationHouse
edge_18,XLD-3673,XB-3047,CONNECTED_TO,LineSegment,StationHouse
edge_19,XLD-3699,HWX-3109,CONNECTED_TO,LineSegment,StationHouse
edge_20,XLD-3699,HWX-3112,CONNECTED_TO,LineSegment,StationHouse
edge_21,XLD-3505,HWX-3109,CONNECTED_TO,LineSegment,StationHouse
edge_22,XLD-3505,XB-3091,CONNECTED_TO,LineSegment,StationHouse
edge_23,XLD-3724,XLKG-3019,CONNECTED_TO,LineSegment,LineSwitch
edge_24,XLD-3724,XLD-3721,CONNECTED_TO,LineSegment,LineSegment
edge_25,XLD-3724,XLD-3722,CONNECTED_TO,LineSegment,LineSegment
edge_26,XLD-3724,XLD-3726,CONNECTED_TO,LineSegment,LineSegment
edge_27,XB-3047,XLD-3673,CONNECTED_TO,StationHouse,LineSegment
edge_28,HWX-3112,XLD-3699,CONNECTED_TO,StationHouse,LineSegment
edge_29,HWX-3112,XLD-3437,CONNECTED_TO,StationHouse,LineSegment
edge_30,HWX-3112,XLD-3666,CONNECTED_TO,StationHouse,LineSegment
edge_31,XB-3091,XLD-3505,CONNECTED_TO,StationHouse,LineSegment
edge_32,XLD-3721,XLD-3724,CONNECTED_TO,LineSegment,LineSegment
edge_33,XLD-3721,ZSB-3017,CONNECTED_TO,LineSegment,StationHouse
edge_34,XLD-3722,XLD-3724,CONNECTED_TO,LineSegment,LineSegment
edge_35,XLD-3726,XLD-3724,CONNECTED_TO,LineSegment,LineSegment
edge_36,XLD-3726,ZSB-3016,CONNECTED_TO,LineSegment,StationHouse
.groovy:
// 属性定义
schema.propertyKey("id").asText().ifNotExist().create();
schema.propertyKey("name").asText().ifNotExist().create();
schema.propertyKey("objectType").asText().ifNotExist().create();
schema.propertyKey("objectHandle").asText().ifNotExist().create();
schema.propertyKey("deviceType").asText().ifNotExist().create();
schema.propertyKey("internalEndpointNo").asInt().ifNotExist().create();
schema.propertyKey("terminalNo").asInt().ifNotExist().create();
schema.propertyKey("usage").asText().ifNotExist().create();
schema.propertyKey("powerFlowDirection").asInt().ifNotExist().create();
schema.propertyKey("belongSubstation").asText().ifNotExist().create();
schema.propertyKey("belongFeeder").asText().ifNotExist().create();
schema.propertyKey("source_label").asText().ifNotExist().create();
schema.propertyKey("target_label").asText().ifNotExist().create();
// 顶点标签
schema.vertexLabel("Substation").properties("id", "name", "objectType",
"objectHandle", "deviceType", "internalEndpointNo", "terminalNo", "usage",
"powerFlowDirection", "belongSubstation",
"belongFeeder").primaryKeys("id").ifNotExist().create();
schema.vertexLabel("LineSegment").properties("id", "name", "objectType",
"objectHandle", "deviceType", "internalEndpointNo", "terminalNo", "usage",
"powerFlowDirection", "belongSubstation",
"belongFeeder").primaryKeys("id").ifNotExist().create();
schema.vertexLabel("LineSwitch").properties("id", "name", "objectType",
"objectHandle", "deviceType", "internalEndpointNo", "terminalNo", "usage",
"powerFlowDirection", "belongSubstation",
"belongFeeder").primaryKeys("id").ifNotExist().create();
schema.vertexLabel("StationHouse").properties("id", "name", "objectType",
"objectHandle", "deviceType", "internalEndpointNo", "terminalNo", "usage",
"powerFlowDirection", "belongSubstation",
"belongFeeder").primaryKeys("id").ifNotExist().create();
// 边标签(每种类型对每种类型都定义一条边,便于扩展和双向连接)
schema.edgeLabel("Substation2LineSegment").sourceLabel("Substation").targetLabel("LineSegment").properties().ifNotExist().create();
schema.edgeLabel("LineSegment2StationHouse").sourceLabel("LineSegment").targetLabel("StationHouse").properties().ifNotExist().create();
schema.edgeLabel("LineSegment2LineSegment").sourceLabel("LineSegment").targetLabel("LineSegment").properties().ifNotExist().create();
schema.edgeLabel("StationHouse2LineSwitch").sourceLabel("StationHouse").targetLabel("LineSwitch").properties().ifNotExist().create();
schema.edgeLabel("LineSegment2LineSwitch").sourceLabel("LineSegment").targetLabel("LineSwitch").properties().ifNotExist().create();
// ...根据实际需要继续补充
// 反向边(如需双向,定义反向边标签)
schema.edgeLabel("LineSegment2Substation").sourceLabel("LineSegment").targetLabel("Substation").properties().ifNotExist().create();
schema.edgeLabel("StationHouse2LineSegment").sourceLabel("StationHouse").targetLabel("LineSegment").properties().ifNotExist().create();
//schema.edgeLabel("LineSegment2LineSegment").sourceLabel("LineSegment").targetLabel("LineSegment").properties().ifNotExist().create();
schema.edgeLabel("LineSwitch2StationHouse").sourceLabel("LineSwitch").targetLabel("StationHouse").properties().ifNotExist().create();
schema.edgeLabel("LineSwitch2LineSegment").sourceLabel("LineSwitch").targetLabel("LineSegment").properties().ifNotExist().create();
// ...以此类推
strcut.json
{
"vertices": [
{
"label": "Substation",
"input": {
"type": "file",
"path":
"/loader/power_data/vertex_substation-1.csv",
"format": "CSV",
"header": ["id", "name", "objectType",
"objectHandle", "deviceType", "internalEndpointNo", "terminalNo", "usage",
"powerFlowDirection", "belongSubstation", "belongFeeder"],
"charset": "UTF-8"
},
"null_values": ["NULL", "null", ""]
},
{
"label": "LineSegment",
"input": {
"type": "file",
"path":
"/loader/power_data/vertex_linesegment-1.csv",
"format": "CSV",
"header": ["id", "name", "objectType",
"objectHandle", "deviceType", "internalEndpointNo", "terminalNo", "usage",
"powerFlowDirection", "belongSubstation", "belongFeeder"],
"charset": "UTF-8"
},
"null_values": ["NULL", "null", ""]
},
{
"label": "LineSwitch",
"input": {
"type": "file",
"path":
"/loader/power_data/vertex_lineswitch-1.csv",
"format": "CSV",
"header": ["id", "name", "objectType",
"objectHandle", "deviceType", "internalEndpointNo", "terminalNo", "usage",
"powerFlowDirection", "belongSubstation", "belongFeeder"],
"charset": "UTF-8"
},
"null_values": ["NULL", "null", ""]
},
{
"label": "StationHouse",
"input": {
"type": "file",
"path":
"/loader/power_data/vertex_stationhouse-1.csv",
"format": "CSV",
"header": ["id", "name", "objectType",
"objectHandle", "deviceType", "internalEndpointNo", "terminalNo", "usage",
"powerFlowDirection", "belongSubstation", "belongFeeder"],
"charset": "UTF-8"
},
"null_values": ["NULL", "null", ""]
}
],
"edges": [
{
"label": "Substation2LineSegment",
"source": ["from"],
"target": ["to"],
"input": {
"type": "file",
"path": "/loader/power_data/power_edges_to.csv",
"format": "CSV",
"header": ["id", "from", "to", "label",
"source_label", "target_label"]
},
"field_mapping": { "from": "from", "to": "to" }
},
{
"label": "LineSegment2Substation",
"source": ["from"],
"target": ["to"],
"input": {
"type": "file",
"path": "/loader/power_data/power_edges_to.csv",
"format": "CSV",
"header": ["id", "from", "to", "label",
"source_label", "target_label"]
},
"field_mapping": { "from": "from", "to": "to" }
},
{
"label": "LineSegment2StationHouse",
"source": ["from"],
"target": ["to"],
"input": {
"type": "file",
"path": "/loader/power_data/power_edges_to.csv",
"format": "CSV",
"header": ["id", "from", "to", "label",
"source_label", "target_label"]
},
"field_mapping": { "from": "from", "to": "to" }
},
{
"label": "StationHouse2LineSegment",
"source": ["from"],
"target": ["to"],
"input": {
"type": "file",
"path": "/loader/power_data/power_edges_to.csv",
"format": "CSV",
"header": ["id", "from", "to", "label",
"source_label", "target_label"]
},
"field_mapping": { "from": "from", "to": "to" }
},
{
"label": "StationHouse2LineSwitch",
"source": ["from"],
"target": ["to"],
"input": {
"type": "file",
"path": "/loader/power_data/power_edges_to.csv",
"format": "CSV",
"header": ["id", "from", "to", "label",
"source_label", "target_label"]
},
"field_mapping": { "from": "from", "to": "to" }
},
{
"label": "LineSwitch2StationHouse",
"source": ["from"],
"target": ["to"],
"input": {
"type": "file",
"path": "/loader/power_data/power_edges_to.csv",
"format": "CSV",
"header": ["id", "from", "to", "label",
"source_label", "target_label"]
},
"field_mapping": { "from": "from", "to": "to" }
},
{
"label": "LineSegment2LineSegment",
"source": ["from"],
"target": ["to"],
"input": {
"type": "file",
"path": "/loader/power_data/power_edges_to.csv",
"format": "CSV",
"header": ["id", "from", "to", "label",
"source_label", "target_label"]
},
"field_mapping": { "from": "from", "to": "to" }
},
{
"label": "LineSegment2LineSwitch",
"source": ["from"],
"target": ["to"],
"input": {
"type": "file",
"path": "/loader/power_data/power_edges_to.csv",
"format": "CSV",
"header": ["id", "from", "to", "label",
"source_label", "target_label"]
},
"field_mapping": { "from": "from", "to": "to" }
},
{
"label": "LineSwitch2LineSegment",
"source": ["from"],
"target": ["to"],
"input": {
"type": "file",
"path": "/loader/power_data/power_edges_to.csv",
"format": "CSV",
"header": ["id", "from", "to", "label",
"source_label", "target_label"]
},
"field_mapping": { "from": "from", "to": "to" }
}
]
}
原始邮件
发件人:dosubot[bot] ***@***.***>
发件时间:2025年12月10日 14:58
收件人:apache/incubator-hugegraph ***@***.***>
抄送:wangzhewwzz ***@***.***>, Mention ***@***.***>
主题:Re: [apache/incubator-hugegraph] 关于电网拓扑数据导入 (Discussion #2917)
你的配置只差一个关键点就能导入成功:struct.json 的 edges 里 field_mapping 必须写成:
"field_mapping": { "from": "from", "to": "to" }
不能写成 { "from": "id", "to": "id" },否则 loader 会把 CSV 的 id 列当作边属性导入,但
schema.groovy 的 edgeLabel 没有声明 id 属性,导致 “Invalid property 'id' for edge label”
或 “主键字段 [id] 为空” 的报错。
详细原因和修正方法:
你的顶点主键是 id(vertex_xxx.csv 里有 id 列,schema 里 primaryKeys("id")),loader 只会用
from/to 字段的值直接作为顶点主键 id,不会再去查 vertex_xxx.csv 的其他字段。
edge_connected_to.csv 的 id 列可以保留,但 loader 不会导入它为边属性,只要 field_mapping 不写 id
就不会报错。
edgeLabel 的 .properties() 只包含 "source_label", "target_label",不要加 "id"。
value_mapping 必须是平铺结构(你现在的写法没问题)。
null_values 建议只保留 ["NULL", "null"],不要加 "",否则空字符串会被判定为 null。
你只需要把 struct.json 里所有 edges 的 field_mapping 全部改成:
"field_mapping": { "from": "from", "to": "to" }
其他配置不用动。这样配置后,边就能正常导入且无报错,所有关系都能导入。官方FAQ说明
如果还有报错,请贴出 power_edges_to.csv 的 header 和前几行原始数据,以及 struct.json 某个 edges
配置的完整内容,我可以帮你定位具体是哪一行或哪一列有问题。
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-15216038
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]