orientdb加载图节点和边缘的csv [英] orientdb load graph csv of nodes and edges
问题描述
我有一个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
}
$ bextractor:{
csv:{}
},
变形金刚:[
{
顶点 :{
class:lac2
}
},
{
顶点:{
class:lac2
$ bedge:
{
class:IsActingWith,
joinFieldName :score_p,
lookup:acore,
direction:out
}
}
],
loader:{
orientdb:{
db URL: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
code $ >
这就是我的尝试,但对我来说似乎并不合逻辑。
我期待的最终结果是让一个graaph由 p1-> ACTINGWITH-> p2
和 ACTINGWITH
得分分数属性
解决方案也许有更好的解决方案,但这是有效的。
我的计划是使用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]}},
变形金刚:[
{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]}},
变形金刚:[
{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}>从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个物品。查询在0.003秒(s)内执行。
orientdb {db = db}>请从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件物品。查询在0.004秒(s)内执行。
I'm a newbie in Orientdb .
I have a csv file which has both the nodes and the edge and I need to create a graph out of that csv file .
csv file
"p1","p2","score"
"LGG_00001","LGG_01682",282
"LGG_00001",".LGG_01831",183
"LGG_00001","LGG_01491",238
The edge is IsActingWith which had the score attribute
{
"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"
},
]
}
}
}
That is what I tried but it does not seem logic to me.
The final result I'm looking for is to have a graaph made of p1->ACTINGWITH-> p2
and ACTINGWITH
has score of the score attribute
解决方案 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).
这篇关于orientdb加载图节点和边缘的csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!