【问题标题】:Gremlin Neptune - order by a property which doesn't exist in all verticesGremlin Neptune - 按所有顶点中不存在的属性排序
【发布时间】:2021-01-15 09:24:57
【问题描述】:

假设我有一个带有“人”顶点的图。 每个顶点都有一个“名称”和“年龄”属性,除了一个。

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

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 来“替换”缺失的属性?谢谢!

【问题讨论】:

    标签: gremlin amazon-neptune


    【解决方案1】:

    您可以使用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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多