在某些情况下,当我将 order().by(...)
与 coalesce(...)
一起使用时,我会得到莫名其妙的结果。
使用标准的现代图形,
gremlin> g.V()
.hasLabel("person")
.out("created")
.coalesce(values("name"), constant("x"))
.fold()
==>[lop,lop,ripple,lop]
但如果我在合并之前按名称排序,我得到 9 lop
而不是 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]
为什么两个查询的元素数量不同?
最佳答案
这看起来像是一个错误 - 我创建了一个 issue in 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()
这似乎工作正常。
关于gremlin order by with coalesce 重复一些值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53482054/