10

I have following graph:

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

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

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

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?

Vasar
  • 395
  • 2
  • 5
  • 15

1 Answers1

13

You can use coalesce():

gremlin> g.V().project('a').by(coalesce(values('a'),constant('default')))
==>[a:default]
==>[a:1]
stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • Ah, yes `constant()` was what I was looking for, but couldn't find. Thank you for answering so quickly! – Vasar Jun 19 '19 at 14:29