如何将引用自身的表导入OrientDB并让它创建边

时间:2015-03-17 17:07:36

标签: etl orientdb

我迷失了如何导入一个引用自身的表格,并创建了正确的边缘。

表' data_lists '有以下字段:

id,parent,title

尝试1:

我在ETL文件中使用了以下变换器json部分:

  "transformers" : [
   { "vertex": { "class": "data_lists"} }
   ,
   { "edge": { "class": "isParent",
                "joinFieldName": "parent",
                "lookup": "data_lists.id",
                "direction": "out"
            }
  ]

但是,这只会创建id等于parent的边。 (某些行将自己作为父级)

尝试2:

查看我尝试的链接文档:

create link isParent from data_lists.parent to data_lists.id

但是这会在行中创建一个属性,就像原始表引用一样。 另一方面,文档说"这不是一般创建链接的方式"

这不会将边创建为isParent类

中的单独行

尝试3:

摆弄不安全的命令我也尝试过:

insert into isParent (in,out) values (select @rid,isParent from data_lists) unsafe

但是没有错误消息就失败了。

那么,任何想法我怎么能做到这一点?

由于

2 个答案:

答案 0 :(得分:0)

尝试使用此代码:

"变压器" :[    {" vertex":{" class":" class_lists"}}    ,    {" edge":{" class":" isParent",                 " joinFieldName":" parent",                 "查找":" data_lists.id",                 "方向":" out",                 " unresolvedLinkAction":" CREATE"             }   ]

答案 1 :(得分:0)

另一个答案部分正确,因为它创建了所有节点,但也导致重复记录。为避免这种情况,我需要使用合并指令

对于记录,这是我使用的完整ETL指令:

{
"config": {
  "log": "debug"
},
"extractor" : {
  "jdbc": { "driver": "com.mysql.jdbc.Driver",
    "url": "jdbc:mysql://localhost/mydb",
    "userName": "myname",
    "userPassword": "mypass",
    "query": "select * from data_lists;" }
},
"transformers" : [
  { "merge": {
      "joinFieldName": "id",
      "lookup": "data_lists.id"
      }
  }
  ,
 { "vertex": { "class": "data_lists"} }
 ,
 { "edge": { "class": "isParent",
      "joinFieldName": "parent",
      "lookup": "data_lists.id",
      "direction": "out",
      "unresolvedLinkAction":"CREATE",
      "if": "parent is not null and parent <> id"
      }
  }
],

"loader" : {
  "orientdb": {
"classes": [{"name": "data_lists", "extends":"V"}, {"name": "isParent", "extends":"E"}],
"dbType": "graph",
"dbAutoDropIfExists": true,
"standardElementConstraints": false,
"dbURL": "plocal:../databases/mydb",
"dbAutoCreate": true,
"indexes": [{"class":"data_lists", "fields":["id:integer"], "type":"UNIQUE_HASH_INDEX" }]
  }
}

}