图表db可以解决我的图形问题吗?

时间:2017-09-14 08:31:44

标签: graph-databases arangodb aql

我有这样的交易数据(pastebin.com/ZswbyVHM):

Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-03T21:39:06+02:00)
...
[INFO] ------------------------------------------------------------------------
[INFO] Building C 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.7.201606060606:prepare-agent (default) @ C ---
...

{"accountId":3,"recordedAt":"2013-12-01T00:00:00.000Z","region":"South","status":"H"} {"accountId":3,"recordedAt":"2014-01-01T00:00:00.000Z","region":"South","status":"A"} {"accountId":3,"recordedAt":"2014-02-01T00:00:00.000Z","region":"South","status":"B"} {"accountId":3,"recordedAt":"2014-03-01T00:00:00.000Z","region":"South","status":"E"} {"accountId":3,"recordedAt":"2014-04-01T00:00:00.000Z","region":"South","status":"C"} 的群组交易可以被视为:

accountId

从上面的视图我想创建一个来自事务集合的状态关系图 可以使用以下属性保留状态顺序{"accountId": 3, "region":"South", "transactions": [ {"recordedAt":"2013-12-01T00:00:00.000Z", "status": "H"}, {"recordedAt":"2014-01-01T00:00:00.000Z", "status": "A"}, {"recordedAt":"2014-02-01T00:00:00.000Z", "status": "B"}] } recordedAt

  • 图表的节点代表状态,隐含地表示状态的顺序。
  • 他们的边缘有accountId,一个具有相同状态的accountId数组以相同的顺序从一个变为另一个。

  • 图表的路径是accountsaccountIdstatus之间的交集(状态顺序)。

Example: Status Relation Graph

  1. 根“A”和“H”有两种状态。

  2. 在0级,

    AccountId 1,2,4具有相同的状态“A”,但AccountId 3除外。

    AccountId 4的路径在此级别结束。

  3. 在第1级,

    AccountId 1,2具有相同的状态“A”,

    AccountId 3具有相同的状态“A”,但来自不同的路径。

    AccountId 1的路径在此级别结束。

  4. 在第2级,

    AccountId 2的状态为“B”。

    AccountId 3具有相同的状态“B”但来自不同的路径。

  5. 在第3级,

    AccountId 2的状态为“A”,而AccountId 3的状态为“E”

  6. 所以我设计了3个边缘集合:

    设计1:每个边是状态顶点之间的关系,使用level来保持事务的顺序。

    level

    设计2:每条边都是具有边缘属性{"_from": "status/root", "_to": "status/A", "level": 0, "accounts": [{"id": 2, "region": "South", "recordedAt": "2012-05-01"}]} {"_from": "status/A" , "_to": "status/A", "level": 1, "accounts": [{"id": 2, "region": "South", "recordedAt": "2012-06-01"}]} {"_from": "status/A" , "_to": "status/B", "level": 2, "accounts": [{"id": 2, "region": "South", "recordedAt": "2012-07-01"}]} {"_from": "status/B" , "_to": "status/A", "level": 3, "accounts": [{"id": 2, "region": "South", "recordedAt": "2012-08-01"}]} {"_from": "status/A" , "_to": "status/G", "level": 4, "accounts": [{"id": 2, "region": "South", "recordedAt": "2012-09-01"}]} {"_from": "status/G" , "_to": "status/G", "level": 5, "accounts": [{"id": 2, "region": "South", "recordedAt": "2012-10-01"}]} {"_from": "status/G" , "_to": "status/H", "level": 6, "accounts": [{"id": 2, "region": "South", "recordedAt": "2012-11-01"}]} {"_from": "status/H" , "_to": "status/D", "level": 7, "accounts": [{"id": 2, "region": "South", "recordedAt": "2012-12-01"}]} {"_from": "status/D" , "_to": "status/A", "level": 8, "accounts": [{"id": 2, "region": "South", "recordedAt": "2013-01-01"}]} {"_from": "status/A" , "_to": "status/A", "level": 9, "accounts": [{"id": 2, "region": "South", "recordedAt": "2013-02-01"}]} 的水平顶点之间的关系。

    status

    设计3:通过添加虚拟顶点(区域,年份)。

    此设计尝试消除{"_from": "level/root", "_to": "level/0", "status": "A", "accounts": [{"id": 2, "region": "South", "recordedAt": "2012-05-01"}]} {"_from": "level/0" , "_to": "level/1", "status": "A", "accounts": [{"id": 2, "region": "South", "recordedAt": "2012-06-01"}]} {"_from": "level/1" , "_to": "level/2", "status": "B", "accounts": [{"id": 2, "region": "South", "recordedAt": "2012-07-01"}]} {"_from": "level/2" , "_to": "level/3", "status": "A", "accounts": [{"id": 2, "region": "South", "recordedAt": "2012-08-01"}]} {"_from": "level/3" , "_to": "level/4", "status": "G", "accounts": [{"id": 2, "region": "South", "recordedAt": "2012-09-01"}]} {"_from": "level/4" , "_to": "level/5", "status": "G", "accounts": [{"id": 2, "region": "South", "recordedAt": "2012-10-01"}]} {"_from": "level/5" , "_to": "level/6", "status": "H", "accounts": [{"id": 2, "region": "South", "recordedAt": "2012-11-01"}]} {"_from": "level/6" , "_to": "level/7", "status": "D", "accounts": [{"id": 2, "region": "South", "recordedAt": "2012-12-01"}]} {"_from": "level/7" , "_to": "level/8", "status": "A", "accounts": [{"id": 2, "region": "South", "recordedAt": "2013-01-01"}]} {"_from": "level/8" , "_to": "level/9", "status": "A", "accounts": [{"id": 2, "region": "South", "recordedAt": "2013-02-01"}]} 以避免过滤对象数组。通过边缘属性过滤更容易。

    accounts
    • graph用于查询:
      1. 通过过滤所有边缘都指定了id的路径来回忆特定{"_from": "level/root" , "_to": "level/South"} {"_from": "level/South", "_to": "level/2012"} {"_from": "level/2016" , "_to": "level/0", "status": "A", "accountId": 1} {"_from": "level/2012" , "_to": "level/0", "status": "A", "accountId": 2} {"_from": "level/2017" , "_to": "level/0", "status": "A", "accountId": 4} {"_from": "level/0" , "_to": "level/1", "status": "A", "accountId": 1} {"_from": "level/0" , "_to": "level/1", "status": "A", "accountId": 2} {"_from": "level/1" , "_to": "level/2", "status": "B", "accountId": 2} {"_from": "level/2" , "_to": "level/3", "status": "A", "accountId": 2} {"_from": "level/3" , "_to": "level/4", "status": "G", "accountId": 2} {"_from": "level/4" , "_to": "level/5", "status": "G", "accountId": 2} {"_from": "level/5" , "_to": "level/6", "status": "H", "accountId": 2} {"_from": "level/6" , "_to": "level/7", "status": "D", "accountId": 2} {"_from": "level/7" , "_to": "level/8", "status": "A", "accountId": 2} {"_from": "level/8" , "_to": "level/9", "status": "A", "accountId": 2} 的状态模式。

    Pseudo AQL:

    accountId
    1. 哪些状态会导致有趣的状态(按地区或年份)?
    2. Pseudo AQL:

      FOR v, e, p IN 1..20 OUTBOUND status/root statusRelations
        FILTER p.edges[*].accountId ALL == id
      RETURN p.edges.status
      
      1. 每年发生的最多状态是什么?
      2. Pseudo AQL:

        FILTER e._to == "status/D" (AND e.region == "North" AND e.year == 2013)
        RETURN SLICE(p.edges[*], -3) // RETURN 3 previous statuses that followed by "D"
        

        我的哪一个设计最适合ArangoDB,可以回答我的疑问?

0 个答案:

没有答案