Gremlin Neptune - 按并非所有顶点都存在的 属性 排序

Gremlin Neptune - order by a property which doesn't exist in all vertices

假设我有一个包含 'person' 个顶点的图。 每个顶点都有一个 'name' 和 'age' 属性,除了一个。

现在我正在尝试按年龄排序:

g.V().order().by('age', asc).valueMap()

但是失败了:

"The property does not exist as the key has no associated value for the provided element: v[328]:age"

看看这个:https://gremlify.com/ybbfwd2hbbc

我怎样才能用比方说 0 来“替换”缺失的属性?谢谢!

您可以使用constant填写缺失值:

g.V().
  order().
    by(coalesce(
        values('age'),
        constant(0)
      ), asc).
  valueMap()

示例:https://gremlify.com/qqhym71jlg

或提前过滤:

g.V().
  .has('age')
  order().
    by('age', asc).
  valueMap()

示例:https://gremlify.com/qqhym71jlg/1