来自查询的OrientDB ETL边缘查找 - 如何访问$ input?

时间:2015-02-08 03:53:08

标签: graph etl orientdb

我正在尝试从我在MongoDB中保留的大型数据集中进行ETL导入。我已经成功导入了顶点,我觉得我还有一点语法误解而不是导入边缘。

我很确定错误发生在这个变换器中:

{"edge":{"class":"Friend", "joinFieldName":"id", 
  "lookup": "select from Character WHERE $input.id IN character_friends",
  "unresolvedLinkAction":"CREATE"}},

所以我试图做的是从id = FOO的文档到其character_friends数组中包含FOO的所有其他文档的边缘。 如果我执行

select from Character WHERE FOO IN character_friends

在浏览器中,我得到了大量的文档,所以我的猜测是我的问题是$ input.id要么不返回我期待的id,要么可能根本没有被识别为变量。

文件如下:

{
  id: FOO,
  character_friends: [BAR, BAZ, QUX]
  (and a bunch of other junk)
}

1 个答案:

答案 0 :(得分:2)

似乎您正在插入属性" id",但它已在蓝图标准中保留。您可以重命名它(使用"字段"变换器)或在Orient Loader中设置它:

  standardElementConstraints: false,

然后我用这个内容创建了文件/temp/datasets/charles.json:

[
 {
  name: "Joe",
  id: 1,
  friends: [2,4,5],
  enemies: [6]
 },
 {
  name: "Suzie",
  id: 2,
  friends: [1,4,6],
  enemies: [5,2]
 }
]

这条管道:

{
  config: {
    log: "debug",
    parallel: false
  },
  source : {
    file: { path: "/temp/datasets/charles.json", lock : true }
  },
  extractor : {
    json: {}
  },
  transformers : [
    { merge: { joinFieldName:"id", lookup:"Account.id" } },
    { vertex: { class: "Account"} },
    { edge: {
      "class": "Friend",
      "joinFieldName": "friends",
      "lookup": "Account.id",
      "unresolvedLinkAction": "CREATE"
    } },
    { edge: {
      "class": "Enemy",
      "joinFieldName": "enemies",
      "lookup": "Account.id",
      "unresolvedLinkAction": "CREATE"
    } }
  ],
  loader : {
    orientdb: {
      dbURL: "plocal:/temp/databases/charles",
      dbUser: "admin",
      dbPassword: "admin",
      dbAutoDropIfExists: true,
      dbAutoCreate: true,
      standardElementConstraints: false,
      tx: false,
      wal: false,
      batchCommit: 1000,
      dbType: "graph",
      classes: [{name: 'Account', extends:"V"}, {name: 'Friend', extends:"E"}, {name: 'Enemy', extends:"E"}],
      indexes: [{class:"Account", fields:["id:integer"], type:"UNIQUE_HASH_INDEX" }]
    }
  }
}

确保使用默认版本的ETL jar的最新版本(在$ ORIENTDB / lib中替换它)。最新版本可从以下网址下载:

https://oss.sonatype.org/content/repositories/snapshots/com/orientechnologies/orientdb-etl/2.0.2-SNAPSHOT/orientdb-etl-2.0.2-20150208.225903-1.jar

或者获得主要的OrientDB ETL 2.0.2。