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

您好,下面是我贴出的脚本、部分数据和报错问题,请麻烦帮我检查一下


schema.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("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("source_label",
 "target_label").ifNotExist().create();
schema.edgeLabel("LineSegment2StationHouse").sourceLabel("LineSegment").targetLabel("StationHouse").properties("source_label",
 "target_label").ifNotExist().create();
schema.edgeLabel("LineSegment2LineSegment").sourceLabel("LineSegment").targetLabel("LineSegment").properties("source_label",
 "target_label").ifNotExist().create();
schema.edgeLabel("StationHouse2LineSwitch").sourceLabel("StationHouse").targetLabel("LineSwitch").properties("source_label",
 "target_label").ifNotExist().create();
schema.edgeLabel("LineSegment2LineSwitch").sourceLabel("LineSegment").targetLabel("LineSwitch").properties("source_label",
 "target_label").ifNotExist().create();
// ...根据实际需要继续补充


// 反向边(如需双向,定义反向边标签)
schema.edgeLabel("LineSegment2Substation").sourceLabel("LineSegment").targetLabel("Substation").properties("source_label",
 "target_label").ifNotExist().create();
schema.edgeLabel("StationHouse2LineSegment").sourceLabel("StationHouse").targetLabel("LineSegment").properties("source_label",
 "target_label").ifNotExist().create();
//schema.edgeLabel("LineSegment2LineSegment").sourceLabel("LineSegment").targetLabel("LineSegment").properties().ifNotExist().create();
schema.edgeLabel("LineSwitch2StationHouse").sourceLabel("LineSwitch").targetLabel("StationHouse").properties("source_label",
 "target_label").ifNotExist().create();
schema.edgeLabel("LineSwitch2LineSegment").sourceLabel("LineSwitch").targetLabel("LineSegment").properties("source_label",
 "target_label").ifNotExist().create();
// ...以此类推


struct.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/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" }
      }
    }
  ]
}


edge_connected_to.csv部分内容:
id
from
to
label
source_label
target_label

edge_1
BDZ-3002
XLD-3445
CONNECTED_TO
Substation
LineSegment

edge_2
XLD-3445
HWX-3087
CONNECTED_TO
LineSegment
StationHouse

edge_3
HWX-3087
XLD-3258
CONNECTED_TO
StationHouse
LineSegment

edge_4
HWX-3087
XLD-3455
CONNECTED_TO
StationHouse
LineSegment

edge_5
XLD-3258
HWX-3109
CONNECTED_TO
LineSegment
StationHouse

edge_6
XLD-3455
XLKG-3019
CONNECTED_TO
LineSegment
LineSwitch

edge_7
HWX-3109
XLD-3673
CONNECTED_TO
StationHouse
LineSegment

edge_8
HWX-3109
XLD-3699
CONNECTED_TO
StationHouse
LineSegment

edge_9
HWX-3109
XLD-3505
CONNECTED_TO
StationHouse
LineSegment

edge_10
XLKG-3019
XLD-3724
CONNECTED_TO
LineSwitch
LineSegment

edge_11
XLD-3673
XB-3047
CONNECTED_TO
LineSegment
StationHouse

edge_12
XLD-3699
HWX-3112
CONNECTED_TO
LineSegment
StationHouse

edge_13
XLD-3505
XB-3091
CONNECTED_TO
LineSegment
StationHouse

edge_14
XLD-3724
XLD-3721
CONNECTED_TO
LineSegment
LineSegment

edge_15
XLD-3724
XLD-3722
CONNECTED_TO
LineSegment
LineSegment

edge_16
XLD-3724
XLD-3726
CONNECTED_TO
LineSegment
LineSegment

edge_17
HWX-3112
XLD-3437
CONNECTED_TO
StationHouse
LineSegment

edge_18
HWX-3112
XLD-3666
CONNECTED_TO
StationHouse
LineSegment

edge_19
XLD-3721
ZSB-3017
CONNECTED_TO
LineSegment
StationHouse

edge_20
XLD-3726
ZSB-3016
CONNECTED_TO
LineSegment
StationHouse

edge_21
XLD-3437
DLFZX-3136
CONNECTED_TO
LineSegment
StationHouse

edge_22
XLD-3666
HWX-3062
CONNECTED_TO
LineSegment
StationHouse

edge_23
DLFZX-3136
XLD-3484
CONNECTED_TO
StationHouse
LineSegment

edge_24
HWX-3062
XLD-3267
CONNECTED_TO
StationHouse
LineSegment

edge_25
HWX-3062
XLD-3264
CONNECTED_TO
StationHouse
LineSegment

edge_26
HWX-3062
XLD-3263
CONNECTED_TO
StationHouse
LineSegment

edge_27
XLD-3484
HWX-3085
CONNECTED_TO
LineSegment
StationHouse

edge_28
XLD-3267
DLFZX-3194
CONNECTED_TO
LineSegment
StationHouse





报错内容:
06:13:22.971 [single-worker-2] ERROR 
org.apache.hugegraph.loader.task.TaskManager - Single insert EDGE error
org.apache.hugegraph.loader.exception.InsertException: Invalid property 'id' 
for edge label 'LineSegment2LineSegment'
        at 
org.apache.hugegraph.loader.task.SingleInsertTask.execute(SingleInsertTask.java:58)
 ~[hugegraph-loader-1.7.0.jar:1.7.0]
        at 
org.apache.hugegraph.loader.task.InsertTask.run(InsertTask.java:89) 
~[hugegraph-loader-1.7.0.jar:1.7.0]
        at 
java.util.concurrent.CompletableFuture$AsyncRun.run(Unknown Source) ~[?:?]
        at 
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) ~[?:?]
        at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) ~[?:?]
        at java.lang.Thread.run(Unknown Source) ~[?:?]
Caused by: org.apache.hugegraph.exception.ServerException: Invalid property 
'id' for edge label 'LineSegment2LineSegment'
        at 
org.apache.hugegraph.exception.ServerException.fromResponse(ServerException.java:45)
 ~[hugegraph-client-1.7.0.jar:1.7.0]
        at 
org.apache.hugegraph.client.RestClient.checkStatus(RestClient.java:194) 
~[hugegraph-client-1.7.0.jar:1.7.0]
        at 
org.apache.hugegraph.rest.AbstractRestClient.post(AbstractRestClient.java:317) 
~[hugegraph-common-1.5.0.jar:1.5.0]
        at 
org.apache.hugegraph.client.RestClient.post(RestClient.java:146) 
~[hugegraph-client-1.7.0.jar:1.7.0]
        at 
org.apache.hugegraph.api.graph.EdgeAPI.create(EdgeAPI.java:55) 
~[hugegraph-client-1.7.0.jar:1.7.0]
        at 
org.apache.hugegraph.driver.GraphManager.addEdges(GraphManager.java:285) 
~[hugegraph-client-1.7.0.jar:1.7.0]
        at 
org.apache.hugegraph.loader.task.InsertTask.insertBatch(InsertTask.java:116) 
~[hugegraph-loader-1.7.0.jar:1.7.0]
        at 
org.apache.hugegraph.loader.task.SingleInsertTask.insertSingle(SingleInsertTask.java:95)
 ~[hugegraph-loader-1.7.0.jar:1.7.0]
        at 
org.apache.hugegraph.loader.task.SingleInsertTask.execute(SingleInsertTask.java:51)
 ~[hugegraph-loader-1.7.0.jar:1.7.0]
        ... 5 more
81/0
--------------------------------------------------
count metrics
    input read success            : 188
    input read failure            : 0
    vertex parse success          : 81
    vertex parse failure          : 0
    vertex insert success         : 81
    vertex insert failure         : 0
    edge parse success            : 963
    edge parse failure            : 0
    edge insert success           : 0
    edge insert failure           : 963
--------------------------------------------------
meter metrics
    total time               
     : 2.349s
    read time                 
    : 0.11s
    load time                 
    : 2.239s
    vertex load time             
 : 0.095s
    vertex load rate(vertices/s)  : 852
    edge load time               
 : 2.144s
    edge load rate(edges/s)       : 0




         原始邮件
         
       
发件人:dosubot[bot] ***@***.***>
发件时间:2025年12月9日 13:29
收件人:apache/incubator-hugegraph ***@***.***>
抄送:wangzhewwzz ***@***.***>, Mention ***@***.***>
主题:Re: [apache/incubator-hugegraph] 关于电网拓扑数据导入 (Discussion #2917)




你只需要在 schema.groovy 里加上这两行即可解决 “属性键'source_label'不存在” 的报错:
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() 
里加上这两个属性,比如:
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 下面,应该是: "value_mapping": {  
 "label": { "CONNECTED_TO": "LineSegment2StationHouse" },  
 "source_label": { "LineSegment": "LineSegment" },   "target_label": 
{ "StationHouse": "StationHouse" } }


修改 schema 后,重新执行 schema 创建和数据导入流程。

官方文档有详细说明:schema.propertyKey 定义示例

如还有问题,可以贴出 struct.json、schema.groovy 和 edge_connected_to.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-15205005

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

Reply via email to