Gremlin中的project()步骤缺少属性时的默认值? [英] Default value when property is missing with project() step in Gremlin?

查看:193
本文介绍了Gremlin中的project()步骤缺少属性时的默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下图形:

g.addV('TEST').property(id, 't1')
g.addV('TEST').property(id, 't2').property('a', 1)

如果我这样做: g.V('t2').project('a').by(values('a'))遍历有效并返回键a的映射,因为这里存在属性.

If I do: g.V('t2').project('a').by(values('a')) the traversal works and returns map with key a because property is there.

但是如果我在遍历中有项目步骤,如下所示: g.V('t1').project('a').by(values('a'))

But if I have project step in my traversal like following: g.V('t1').project('a').by(values('a'))

因为缺少a会返回错误,在这种情况下是否有任何方法可以从by()步骤返回null或空值来避免此错误?

Because a is missing it returns error, is there any way to return null or empty value in such case from by() step to avoid this error?

推荐答案

您可以使用coalesce():

gremlin> g.V().project('a').by(coalesce(values('a'),constant('default')))
==>[a:default]
==>[a:1]

这篇关于Gremlin中的project()步骤缺少属性时的默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆