cassandra - 基于聚合的日期顶点从不同的顶点获取标签
问题描述
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
.
解决方案
您的所有查询都丢失了,这是一个额外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]
推荐阅读
- node.js - Docker 错误:Parcel (Parceljs) 在 Docker 中不起作用
- reactjs - 反应本机 useContext 返回未定义
- c# - 模型 ASP.Net mvc 中未设置数据
- amazon-web-services - Amazon SP-API 终端节点通过订单 ID 获取账单地址
- c++ - std::visit 无法推断 std::variant 的类型
- javascript - Html2canvas base 64图形背景黑色
- plotly - Plotly DASH 教程 --> 在 Twitter 情绪分析中回调缺失的输入
- mysql - 使用 Python 3.7 将查询字符串从 AWS 网关传递到 AWS lambda 中的子查询
- python - 如何从句子中删除括号和空格?
- node.js - Angularjs 和 Gulp 运行时出错