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

OrientDB ETL edge lookup from query - how to access $input?

我正在尽最大努力从我一直保存在 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)
}

您似乎要插入 属性 "id",但它已在蓝图标准中保留。您可以重命名它(使用 "field" 转换器)或在 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

或者获取major的OrientDB ETL 2.0.2