Zhongmin
Zhongmin

Reputation: 1751

Gremlin - AWS Neptune - issue when Order by property which does not exist on a vertex

g.V().hasLabel('Asset').order().by('anyprop',decr).valueMap(true)

sometimes it throws error:

UnsupportedOperationException\",\"detailedMessage\":\"Encountered a traverser that does not map to a value for child traversal: value(anyprop)

my guess is there are some vertex does not have 'anyprop' property.

I dynamically generate the query, so 'anyprop' could be any property, how do I avoid this error?

Upvotes: 0

Views: 213

Answers (1)

Kelvin Lawrence
Kelvin Lawrence

Reputation: 14371

When Neptune moves up to the 3.5.x Apache TinkerPop level there are some changes to the way Gremlin handles cases like this that will stop the error from happening. In the near term, you can just use a coalesce to sort by a default value in cases where the key does not exist. Note I changed decr to desc as decr is deprecated now.

g.V().hasLabel('Asset').
      order().
        by(coalesce(values('anyprop'),constant(0)),desc).
      valueMap(true).limit(3)

Upvotes: 1

Related Questions