【问题标题】:Aggregation based date vertex to get label from different vertex基于聚合的日期顶点从不同的顶点获取标签
【发布时间】:2019-05-15 09:07:41
【问题描述】:
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 顶点。我正在尝试基于来自l1submit_time 属性聚合上述场景。我已经尝试了以下查询。

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,但是我的jobdesc 为空,因为它不满足“有”条件.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 映射索引。

【问题讨论】:

  • 仅供参考:您的问题没有被黑魔法格式化和修复,实际上有人花时间为您做这件事。下一次,你在 SO 上发布一个问题,确保它的格式正确并且代码 sn-ps 确实有效。
  • 给您带来的不便,我们深表歉意。下次我一定会照顾它的。

标签: cassandra gremlin tinkerpop3


【解决方案1】:

您的所有查询都丢失了,是一个额外的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]

【讨论】:

  • 感谢您的快速回复。它解决了我的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-06-15
  • 2017-10-24
  • 1970-01-01
  • 2020-09-28
  • 2017-06-27
  • 2017-10-19
  • 2020-01-07
相关资源
最近更新 更多