orientdb load graph csv of nodes and edges

醉酒当歌 提交于 2019-11-29 17:30:02

maybe there's a better solution but this works. My plan is to use 3 different etl scripts: first and second for inserting the vertices and the third for the edges. Of course you'll need to execute them in order.

vertex_import_p1.json

{
    "source": { "file": { "path": "/home/ivan/Cose/OrientDB/issues/stack/44641116/file.csv" } },
    "extractor": { "csv": {
        "separator": ",",
    "columns": ["p1:String","p2:String","s:Integer"] } },
    "transformers": [
        { "command": { "command": "UPDATE lac2 set p='${input.p1}' UPSERT WHERE p='${input.p1}'"} }      
    ],
    "loader": {
        "orientdb": {
            "dbURL": "plocal:/home/ivan/Cose/OrientDB/issues/stack/44641116/db",
            "dbUser": "admin",
            "dbPassword": "admin",
            "dbType": "graph",
            "classes": [
                {"name": "lac2", "extends": "V"},
                {"name": "isActingWith", "extends": "E"}
            ]
        }
    }
}

vertex_import_p2.json

{
    "source": { "file": { "path": "/home/ivan/Cose/OrientDB/issues/stack/44641116/file.csv" } },
    "extractor": { "csv": {
        "separator": ",",
    "columns": ["p1:String","p2:String","s:Integer"] } },
    "transformers": [
        { "command": { "command": "UPDATE lac2 set p='${input.p2}' UPSERT WHERE p='${input.p2}'"} }      
    ],
    "loader": {
        "orientdb": {
            "dbURL": "plocal:/home/ivan/Cose/OrientDB/issues/stack/44641116/db",
            "dbUser": "admin",
            "dbPassword": "admin",
            "dbType": "graph",
            "classes": [
                {"name": "lac2", "extends": "V"},
                {"name": "isActingWith", "extends": "E"}
            ]
        }
    }
}

edge_import_s.json

{
    "source": { "file": { "path": "/home/ivan/Cose/OrientDB/issues/stack/44641116/file.csv" } },
    "extractor": { "csv": {
        "separator": ",",
    "columns": ["p1:String","p2:String","s:Integer"] } },
    "transformers": [
        { "command": { "command": "CREATE EDGE isActingWith FROM (SELECT FROM lac2 WHERE p='${input.p1}') TO (SELECT FROM lac2 WHERE p='${input.p2}') set score=${input.s}"} }
    ],
    "loader": {
        "orientdb": {
            "dbURL": "plocal:/home/ivan/Cose/OrientDB/issues/stack/44641116/db",
            "dbUser": "admin",
            "dbPassword": "admin",
            "dbType": "graph",
            "classes": [
                {"name": "lac2", "extends": "V"},
                {"name": "isActingWith", "extends": "E"}
            ]
        }
    }
}

And here are the situation after the executions:

orientdb {db=db}> select from lac2

+----+-----+------+---------+-------------------+---------------+
|#   |@RID |@CLASS|p        |out_isActingWith   |in_isActingWith|
+----+-----+------+---------+-------------------+---------------+
|0   |#21:6|lac2  |LGG_00001|[#25:5,#26:1,#27:1]|               |
|1   |#21:7|lac2  |LGG_01682|                   |[#25:5]        |
|2   |#22:3|lac2  |LGG_01831|                   |[#26:1]        |
|3   |#23:1|lac2  |LGG_01491|                   |[#27:1]        |
+----+-----+------+---------+-------------------+---------------+

4 item(s) found. Query executed in 0.003 sec(s).
orientdb {db=db}> select from isActingWith

+----+-----+------------+-----+-----+-----+
|#   |@RID |@CLASS      |score|out  |in   |
+----+-----+------------+-----+-----+-----+
|0   |#25:5|isActingWith|282  |#21:6|#21:7|
|1   |#26:1|isActingWith|183  |#21:6|#22:3|
|2   |#27:1|isActingWith|238  |#21:6|#23:1|
+----+-----+------------+-----+-----+-----+

3 item(s) found. Query executed in 0.004 sec(s).
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!