Warm tip: This article is reproduced from stackoverflow.com, please click
gremlin amazon-neptune

How, with Gremlin, to return properties from in-vertices the same as I do from out-vertices? (Not as

发布于 2020-03-27 10:21:57

I'm trying to start traversing from one set of labelled vertices, then get all their in-vertices connected by a particular kind of edge, then from there, return a property of those in-vertices as objects. I can do this same thing with some out-vertices starting from the same set of labelled vertices with no problem, but get a "The provided traverser does not map to a value:" error when I attempt it with some in-vertices.

I have found a workaround, but it is not ideal, as it returns the desired property values as arrays of length one.

Here is how I do the very similar task successfully with out-vertices: g.V().hasLabel('TestCenter').project('address').by(out('physical').project('street').by(values('street1')))

This returns things like

==>{address={street=561 PLACE DE CEDARE}}
==>{address={street=370 N BLACK STATION AVE}}

This is great!

Then I try the same sort of query with some in-vertices, like this: g.V().hasLabel('TestCenter').project('host').by(__.in('hosts').project('aCode').by(values('code'))) and get the above mentioned error.

The workaround I've been able to find is to add a .fold() to the final "by" like this: g.V().hasLabel('TestCenter').project('host').by(__.in('hosts').project('aCode').by(values('code')).fold()) but then my responses are like this

==>{host=[{aCode=7387}]}
==>{host=[{aCode=9160}]}

What I would like is a response looking like this:

==>{host={aCode=4325}}
==>{host={aCode=1234}}

(Note: I am not sure if this is relevant, but I am connecting Gremlin to a Neptune DB Instance)

Questioner
jupiterjelly
Viewed
25
noam621 2019-07-03 22:17

It seems to me from the error above and your workaround that not all of your 'TestCenter' have an in edge from type 'hosts'. When using project the by have to map for a valid value.

you can do two things:

1) make sure a value will be returned in the project:

g.V().hasLabel('TestCenter').project('host')
     .by(coalesce(__.in('hosts').project('aCode').by(values('code')), constant('empty')))

2) filter does values:

g.V().hasLabel('TestCenter').where(__.in('hosts'))
.project('host').by(__.in('hosts').project('aCode').by(values('code')))