首页 > 解决方案 > 基于聚合的日期顶点从不同的顶点获取标签

问题描述

g.addV('l1').
    property(id, 12347).
    property('submit_time', new Date('Wed May14 10:00:00 PDT 2019')).
  addV('l1').
    property(id, 4522323).
    property('submit_time', new Date('Wed May15 11:00:00 PDT 2019')).
  addV('l1').
    property(id, 2355208312).
    property('submit_time', new Date('Wed May15 11:00:00 PDT 2019')).
  addV('l3').
    property(id, 45678).
    property('start_time', new Date('Fri Apr 24 07:01:36 PDT 2019')).
  addV('l3').
    property(id, 67892).
    property('start_time', new Date('Fri Apr 24 07:01:36 PDT 2019')).
  addV('l3').
    property(id, 678954).
    property('start_time', new Date('Fri Apr 26 23:01:36 PDT 2019')).
    property('condition', "somevalue").
  addE('e1').
    from(V(12347)).
    to(V(45678)).
  addE('e1').
    from(V(12347)).
    to(V(67892)).
  addE('e1').
    from(V(4522323)).
    to(V(678954)).
  addE('e1').
    from(V(2355208312)).
    to(V(45678)).
  iterate()

一个l1顶点可以与一条边 ( e1) 关联到多个不同的l3顶点。我正在尝试根据submit_time来自l1. 我已经尝试了以下查询。

g.V().hasLabel("l1").
  group().
    by(map {(it.get().value("submit_time").getYear() + 1900) + "/" +
            (it.get().value("submit_time").getMonth() + 1) + "/" +
             it.get().value("submit_time").getDate()}).
  unfold().
  project('submitdate','job','jobdesc').
    by(keys).
    by(values).
    by(select(values).unfold().out('e1').has("condition","somevalue").fold()).
  order(local).
    by(keys, incr)

它让我得到以下结果。

==>[job:[v[12347]],jobdesc:[],submitdate:2019/5/14]
==>[job:[v[2355208312],v[4522323]],jobdesc:[v[678954]],submitdate:2019/5/15]

在上面的结果中,它基于聚合后submitdate得到它的相应l1顶点job,但是 myjobdesc是空的,因为它不满足 "has" 条件.has("condition","somevalue")

在第一个结果中,即使顶点v[12347]被考虑在聚合中,并且有一个边缘v[45678]并且v[67892]它们不满足“有条件”,所以我jobdesc是空的。同样在第二个结果中,我的一个顶点 ( v[678954]) 满足上述条件。

谁能帮我获得一些默认值,例如。jobdesc如果每个作业顶点不满足条件并被考虑在聚合中,则为每个作业顶点创建一个空数组?

预期产出

==>[job:[v[12347]],jobdesc:[[]],submitdate:2019/5/14]
==>[job:[v[2355208312],v[4522323]],jobdesc:[[],v[678954]],submitdate:2019/5/15]

例如:v[2355208312]被考虑在聚合中,submitdate 2019/5/14但没有jobdesc它,所以我无法映射每个作业的索引及其对应的jobdesc.

标签: cassandragremlintinkerpop3

解决方案


您的所有查询都丢失了,这是一个额外map()fold()步骤。

gremlin> g.V().hasLabel("l1").
           group().
             by(map {(it.get().value("submit_time").getYear()  + 1900) + "/" +
                     (it.get().value("submit_time").getMonth() +    1) + "/" +
                      it.get().value("submit_time").getDate()}).
           unfold().
           project('submitdate','job','jobdesc').
             by(keys).
             by(values).
             by(select(values).unfold().
                map(out('e1').has("condition","somevalue").fold()). /* for each job */
                fold()).
           order(local).
             by(keys, incr)
==>[job:[v[12347]],jobdesc:[[]],submitdate:2019/5/14]
==>[job:[v[4522323],v[2355208312]],jobdesc:[[v[678954]],[]],submitdate:2019/5/15]

推荐阅读