orientdb加载图csv的节点和边

时间:2017-06-19 22:50:35

标签: csv graph import etl orientdb

我是Orientdb的新手。 我有一个csv文件,它有节点和边缘,我需要从该csv文件中创建一个图形。 csv文件

"p1","p2","score"
"LGG_00001","LGG_01682",282
"LGG_00001",".LGG_01831",183
"LGG_00001","LGG_01491",238

边缘是IsActingWith,它具有得分属性

{
"source": {
    "file": {
        "path": "C:/Users/sams/Desktop/OrientDB2/lac2.csv"
    }
},
"extractor": {
    "csv": {}
},
"transformers": [
    {
        "vertex": {
            "class": "lac2"
        }
    },
    {
        "vertex": {
            "class": "lac2"
        }
    },

    {
        "edge":
        {
                "class": "IsActingWith",
                "joinFieldName": "score_p",
                "lookup": "acore",
                "direction": "out"
        }
    }

],
"loader": {
    "orientdb": {
        "dbURL": "plocal:C:/Users/sams/Desktop/OrientDB2/database/proj",
        "dbType": "graph",
        "dbAutoCreate": true,
        "classes": [
            {
                "name": "lac2",
                "extends": "V"
            },
            {
                "name": "lac2",
                "extends": "V"
            },
            {
                "name": "IsActingWith",
                "extends": "E"
            },

        ]

    }
}
}

这就是我的尝试,但这对我来说似乎不合逻辑。 我正在寻找的最终结果是使用p1->ACTINGWITH-> p2ACTINGWITH得到的graaph得分得分属性

1 个答案:

答案 0 :(得分:2)

也许有更好的解决方案,但这有效。 我的计划是使用3个不同的etl脚本:第一个和第二个用于插入顶点,第三个用于边缘。当然,您需要按顺序执行它们。

<强> 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"}
            ]
        }
    }
}

以下是执行后的情况:

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).