gremlin - gremlin order by with coalesce 重复了一些值
问题描述
在某些情况下,当我使用order().by(...)
with时会得到莫名其妙的结果coalesce(...)
。使用标准的现代图,
gremlin> g.V()
.hasLabel("person")
.out("created")
.coalesce(values("name"), constant("x"))
.fold()
==>[lop,lop,ripple,lop]
但是,如果我在合并之前按名称排序,我会得到 9lop
而不是 3:
gremlin> g.V()
.hasLabel("person")
.out("created")
.order().by("name")
.coalesce(values("name"), constant("x"))
.fold()
==>[lop,lop,lop,lop,lop,lop,lop,lop,lop,ripple]
为什么两个查询之间的元素数量不同?
解决方案
这看起来像一个错误 - 我在 JIRA 中创建了一个问题。有一种解决方法,但首先要考虑到即使将错误放在一边,您的遍历也不会真正起作用,order()
因为您引用了by()
调制器中可能不存在的键,所以会失败。因此,您需要以不同的方式考虑这一点:
g.V().
hasLabel("person").
out("created").
order().by(coalesce(values('name'),constant('x')))
然后我曾经choose()
做coalesce()
应该做的事情:
g.V().
hasLabel("person").
out("created").
order().by(coalesce(values('name'),constant('x'))).
choose(has("name"),values('name'),constant('x')).
fold()
这似乎工作正常。
推荐阅读
- google-chrome-extension - 在不同的网站上创建面板
- arm - 如何使用 ARM XML 机器可读架构规范进行汇编和反汇编?
- javascript - Puppeteer 抓取极慢
- android - 以编程方式将样式应用于 MaterialButton
- docker - 在不使用 localectl 的情况下更改 CentOS/RHEL 中的系统区域设置?
- javascript - 在打字稿中,返回 void 函数的函数的返回类型是什么?
- oracle-sqldeveloper - 无法启动 SQL Developer 4.2
- json - 在scala play中重构一个json
- angular - 该请求必须是有效的 CORS 请求,并且需要包含“Origin”标头。角
- c# - 使用 JsonConvert.SerializeObject C# 时出现 JSON 结果问题