How to get NULL as COALESCE VALUE

566 views
Skip to first unread message

Sanjay Sharma

unread,
Mar 13, 2019, 3:12:34 PM3/13/19
to Gremlin-users
I am using COALESCE to return the alternate value if a traversal does not exists. below is the query

g.V('machine1').project('machine', 'make').by(identity()).by(coalesce(out('ofMake'), constant('null'))

this works just fine but when i use this query in java gremlin driver, i get back following JAVA TYPES in the RESULT object,

Machine as DetachedVertex type
Make as java.lang.String with value NULL, and if it exists then DetachedVertex type.

This makes me do few if's and else in my code, Is it possible to make query return NULL as an OBJECT instead of String , so that i can simple check NOT NULL condition ? 





Daniel Kuppitz

unread,
Mar 13, 2019, 6:28:55 PM3/13/19
to gremli...@googlegroups.com
Using nulls in traversals is a bad idea as it mostly won't work. You can rewrite your traversal though:

g.V('machine1').
  choose(outE('ofMake'),
           __.project('machine','make').
                by().
                by(out('ofMake')),
           __.project('machine'))

Then make wouldn't be part of the map, but at least in Java result.get('make') would return null and I guess that's all you need.

Cheers,
Daniel


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/ec05aae0-c145-4798-b57c-6fcce4f9ce02%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages