GitHub user wangzhewwzz added a comment to the discussion: 关于电网拓扑数据导入
按您说的还是有问题 代码贴了如下
>> HugeGraphLoader worked in NORMAL MODE
vertices/edges loaded this time : 07:53:51.400 [batch-worker-5] ERROR
org.apache.hugegraph.loader.task.TaskManager - server exception: Invalid
property 'source_label' for edge label 'Substation2LineSegment'
07:53:51.400 [batch-worker-7] ERROR
org.apache.hugegraph.loader.task.TaskManager - server exception: Invalid
property 'source_label' for edge label 'LineSegment2StationHouse'
07:53:51.400 [batch-worker-6] ERROR
org.apache.hugegraph.loader.task.TaskManager - server exception: Invalid
property 'source_label' for edge label 'LineSegment2Substation'
07:53:51.404 [batch-worker-8] ERROR
org.apache.hugegraph.loader.task.TaskManager - server exception: Invalid
property 'source_label' for edge label 'StationHouse2LineSegment'
07:53:51.414 [batch-worker-9] ERROR
org.apache.hugegraph.loader.task.TaskManager - server exception: Invalid
property 'source_label' for edge label 'StationHouse2LineSwitch'
07:53:51.419 [batch-worker-10] ERROR
org.apache.hugegraph.loader.task.TaskManager - server exception: Invalid
property 'source_label' for edge label 'LineSwitch2StationHouse'
07:53:51.422 [batch-worker-11] ERROR
org.apache.hugegraph.loader.task.TaskManager - server exception: Invalid
property 'source_label' for edge label 'LineSegment2LineSegment'
07:53:51.432 [batch-worker-12] ERROR
org.apache.hugegraph.loader.task.TaskManager - server exception: Invalid
property 'source_label' for edge label 'LineSegment2LineSwitch'
07:53:51.443 [batch-worker-13] ERROR
org.apache.hugegraph.loader.task.TaskManager - server exception: Invalid
property 'source_label' for edge label 'LineSwitch2LineSegment'
07:53:51.434 [single-worker-7] ERROR
org.apache.hugegraph.loader.task.TaskManager - Single insert EDGE error
org.apache.hugegraph.loader.exception.InsertException: Invalid property
'source_label' for edge label 'LineSegment2LineSegment'
// 属性定义
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("label").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();
// ...以此类推
{
"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/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": "Substation2LineSegment"},
"source_label": { "Substation": "Substation" },
"target_label": { "LineSegment": "LineSegment" }
}
},
{
"label": "LineSegment2Substation",
"source": ["to"],
"target": ["from"],
"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":
"LineSegment2Substation" },
"source_label": { "LineSegment":
"LineSegment" },
"target_label": { "Substation": "Substation" }
}
},
{
"label": "LineSegment2StationHouse",
"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":
"LineSegment2StationHouse" },
"source_label": { "LineSegment": "LineSegment" },
"target_label": { "StationHouse": "StationHouse" }
}
},
{
"label": "StationHouse2LineSegment",
"source": ["to"],
"target": ["from"],
"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":
"StationHouse2LineSegment" },
"source_label": { "StationHouse": "StationHouse" },
"target_label": { "LineSegment": "LineSegment" }
}
},
{
"label": "StationHouse2LineSwitch",
"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":
"StationHouse2LineSwitch"},
"source_label": { "StationHouse": "StationHouse" },
"target_label": { "LineSwitch": "LineSwitch" }
}
},
{
"label": "LineSwitch2StationHouse",
"source": ["to"],
"target": ["from"],
"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":
"LineSwitch2StationHouse" },
"source_label": { "LineSwitch": "LineSwitch" },
"target_label": { "StationHouse": "StationHouse" }
}
},
{
"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" }
}
},
{
"label": "LineSegment2LineSwitch",
"source": ["to"],
"target": ["from"],
"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": "LineSegment2LineSwitch"
},
"source_label": { "LineSegment": "LineSegment" },
"target_label": { "LineSwitch": "LineSwitch" }
}
},
{
"label": "LineSwitch2LineSegment",
"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": "LineSwitch2LineSegment"
},
"source_label": { "LineSwitch": "LineSwitch" },
"target_label": { "LineSegment": "LineSegment" }
}
}
]
}
原始邮件
发件人:dosubot[bot] ***@***.***>
发件时间:2025年12月9日 15:44
收件人:apache/incubator-hugegraph ***@***.***>
抄送:wangzhewwzz ***@***.***>, Mention ***@***.***>
主题:Re: [apache/incubator-hugegraph] 关于电网拓扑数据导入 (Discussion #2917)
你的 value_mapping 写法是对的,但你的配置还有两个关键点需要修正,否则边会全部插入失败:
field_mapping 只写 from/to,不要写 id
struct.json 的 edges 里 field_mapping 应该这样写:
"field_mapping": { "from": "id", "to": "id" }
不要把 id 字段导入为边属性,除非 edgeLabel 的 .properties() 里有 id(绝大多数场景不需要)。
schema.groovy 的 edgeLabel .properties() 只写 source_label、target_label,不要加 id
比如:
schema.edgeLabel("LineSegment2LineSegment")
.sourceLabel("LineSegment") .targetLabel("LineSegment")
.properties("source_label", "target_label")
.ifNotExist().create();
不要写 .properties("id", "source_label", "target_label"),否则 loader 会报 “Invalid
property 'id' for edge label”。
value_mapping 必须是平铺结构
你的写法没问题,保持这样:
"value_mapping": { "label": { "CONNECTED_TO": "LineSegment2LineSegment"
}, "source_label": { "LineSegment": "LineSegment" },
"target_label": { "LineSegment": "LineSegment" } }
edge_connected_to.csv 的 source_label/target_label 必须和顶点 label 完全一致(区分大小写)
比如 from=XLD-3445 在 vertex_linesegment-1.csv 里,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 完全一致
这样配置后,边就能正常导入且无报错,所有关系都能导入。详细机制见官方文档。
如还有具体报错,可以贴出 struct.json/schema.groovy/CSV 的片段,我可以帮你逐条检查。
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-15205677
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]