0

I am getting the following error, because some of the vertexes don't have the expected property.

The property does not exist as the key has no associated value for the provided element

Query:-

get_g().V().hasLabel(search_vertex).has(T.id, TextP.containing(search_text)).limit(limit). 
        as_('property_value').inE('owns').outV().as_('id', 'name')
        .select('property_value', 'id', 'name').by(T.id).by(T.id).by('name').toList()
     

How to avoid exception and return NULL or empty space, if the expected property doesn't exist

Thirumal
  • 8,280
  • 11
  • 53
  • 103

1 Answers1

1

In version of TinkerPop before 3.5.0 you can accomplish this using coalesce() (details here) and constant() (details here) steps to return a specific value in the case that a value does not exist as shown here:

gremlin> g.V().as('a').select('a').by(coalesce(values('age'), constant('foo')))
==>29
==>27
==>foo
==>32
==>foo
==>35

In versions after 3.5 this is no longer required as null will now be returned for these values, assuming the database supports this, as shown here:

gremlin> g.V().as('a').select('a').by(values('age'))
==>29
==>27
==>null
==>32
==>null
==>35

Additional details on this change can be found in this post on the Gremlin users group: https://groups.google.com/g/gremlin-users/c/aoaA25H1IE0/m/gTu1MqR1AQAJ

bechbd
  • 6,206
  • 3
  • 28
  • 47