Using the Titan 1.0.0 Gremlin shell I can retrieve a single property value from an edge from within a closure. But trying to access the valueMap()
fails with an exception.
Works:
gremlin> t.E().hasLabel("TRUSTS").has('NOT_VALID_BEFORE').each( { trustEdge -> t.E().has('EDGE_GROUP_ID', trustEdge.value('EDGE_GROUP_ID')).hasNot('NOT_VALID_BEFORE').each({println it.value('EDGE_ID')}) } )
Yields exception (only difference is in the right most closure 'it.valueMap()' vs 'it.value('..')'):
gremlin> t.E().hasLabel("TRUSTS").has('NOT_VALID_BEFORE').each( { trustEdge -> t.E().has('EDGE_GROUP_ID', trustEdge.value('EDGE_GROUP_ID')).hasNot('NOT_VALID_BEFORE').each( { println it.valueMap() } ) } )
No signature of method: com.thinkaurelius.titan.graphdb.relations.StandardEdge.valueMap() is applicable for argument types: () values: []
Possible solutions: value(java.lang.String)
Display stack trace? [yN]
gremlin>
But it is not that in general I would be unable to get to the valueMap of the edge:
gremlin> t.E().hasLabel("TRUSTS").has('NOT_VALID_BEFORE').each( { trustEdge -> t.E().has('EDGE_GROUP_ID', trustEdge.value('EDGE_GROUP_ID')).hasNot('NOT_VALID_BEFORE').each( { println it } ) } )
e[215rmh-oe094-1d05-9i0][40964296-MANAGED->12312]
gremlin> t.E('215rmh-oe094-1d05-9i0').valueMap()
==>[MANAGE_INFORM:false, NOT_VALID_AFTER:1669873006000, MANAGE_MANAGERS:false, MANAGE_AUTHENTICATION_MEANS:true, CREATED_AT:1487683094863, RELATIONSHIP_ROLE:FAMILY_DOCTOR, MANAGE_TRUST:true, UPDATED_AT:1487683094915, MANAGE_REPRESENTATION:false, EDGE_ID:122881049, VERIFIED:true, EDGE_GROUP_ID:122881049]
Is this a bug or am I doing something wrong here?
A little context, just in case the query does not even do what I think it does: What I think I am doing here is looking up all edges with label "TRUSTS" that have a property NOT_VALID_BEFORE. For each of those edges I look up all edges that share the same edge group ID value and check if they also have a property NOT_VALID_BEFORE, printing those to the console that do not have the property set.
When you start iterating with each()
, every item you manipulate inside the closure is "off the traversal" -- that is, you're working with an Edge
object, not an GraphTraversal
object.
Edge
has a value()
method similar to the GraphTraversal
, but it does not have a valueMap()
method. You could use ElementHelper.propertyValueMap()
instead.
Here's a quick example:
gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.E().valueMap()
==>[weight:0.5]
==>[weight:1.0]
==>[weight:0.4]
==>[weight:1.0]
==>[weight:0.4]
==>[weight:0.2]
gremlin> g.E().each{ edge -> println ElementHelper.propertyValueMap(edge) };[]
[weight:0.5]
[weight:1.0]
[weight:0.4]
[weight:1.0]
[weight:0.4]
[weight:0.2]