gremlin order by with coalesce 重复一些值

gremlin order by with coalesce duplicates some values

在某些情况下,当我将 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()

这似乎工作正常。