2

我正在创建一个通信图。
每条消息都有一个 msgid,每个人都有一个用户 ID。
我已经创建了消息顶点,现在我想创建用户顶点和将消息顶点连接到用户顶点的边。
一个用户可以收到多条消息(显然)。
我的文件包含:
msgid、用户 ID(以及我将分配给边缘的一些其他信息)

我遇到的问题是在我的文件中我有重复的用户 ID(因为用户可以获得多条消息),我不想使用用户 ID 创建另一个顶点,所以我跳过重复。但是,如果我确实跳过重复项,则也不会创建边缘。我确实想要同一个用户顶点的多条边,因为每条边代表一条消息。

我如何保持用户顶点唯一但创建边缘?

我当前的 ETL .json 文件可以正常工作,除了我上面详述的内容。

{
 "source": { "file": { "path": "msgs.txt" } },
  "extractor": { "row": {} },
  "transformers": [
    { "csv": {"separator": "\t"} },
      { "vertex": { "class": "user", "skipDuplicates": true  } },
    { "edge": { "class": "sent_to", "joinFieldName": "msgid", "lookup":"message.id","direction": "in"   } },
    "edgeFields": { "n": "${input.n}" }


  ],
  "loader": {
    "orientdb": {
       "dbURL": "remote:/localhost/databases/communication",
       "dbType": "graph",
       "classes": [
         {"name": "user",    "extends":  "V"},
         {"name": "message", "extends": "V"},
         {"name": "sent_to",     "extends":  "E"}
       ], "indexes": [
         {"class":"user", "fields":["id"], "type":"UNIQUE" }
       ]
    }
  }
}
4

1 回答 1

2

好的,这就是我所做的,它似乎有效。
首先,我创建了消息顶点(如上所述,在 q. 中)。
然后我创建了用户顶点。
然后为了在它们之间创建边缘,我在具有 {userid, msgid, ...} 的文件上运行了以下 ETL

{

  "source": { "file": { "path": "msgs1.txt" } },
  "extractor": { "row": {} },
  "transformers": [
    { "csv": {"separator": "\t"} },
    { "merge": {"joinFieldName": "userid", "lookup": "user.id"} },
    { "vertex": { "class": "user", "skipDuplicates": true  } },
    { "edge": { "class": "sent_to",
                "joinFieldName": "msgid",
                "lookup":"message.id",
                "direction": "in",
                "edgeFields": { "n": "${input.n}",  "date": "${input.date}"}
              }
    }

  ],
  "loader": {
    "orientdb": {
       "dbURL": "remote:/localhost/databases/communication",
       "dbType": "graph",
       "classes": [
         {"name": "user",    "extends":  "V"},
         {"name": "message", "extends": "V"},
         {"name": "sent_to",     "extends":  "E"}
       ],
        "indexes": [
       ]
    }
  }
}

这创建了所有边,即使有不止一个边指向用户。
希望这会帮助某人

于 2016-06-15T18:54:36.620 回答