Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve a property value of a vertex in python gremlin

It might be easy, but I am really struggling with this problem. I use gremlin python lib and aws neptune db. I know the vertex id, I just want to get the value(String type in python) of one of the properties of the vertex, and update it.

I have tried to do like this:

print(g.V(event['securityEventManagerId']).values('sourceData'))
print(g.V(event['securityEventManagerId']).property('sourceData'))
print(g.V(event['securityEventManagerId']).property('sourceData').valueMap())
.....

But I just print some python gremlin object like GraphTraversal, cannot retrieve the value as a string

Can anyone help me out?

like image 904
Hongli Bu Avatar asked Jan 25 '23 18:01

Hongli Bu


2 Answers

You must use a terminal step, without them your query will not execute.

From tinkerpop documentation:

Typically, when a step is concatenated to a traversal a traversal is returned. In this way, a traversal is built up in a fluent, monadic fashion. However, some steps do not return a traversal, but instead, execute the traversal and return a result. These steps are known as terminal steps (terminal) and they are explained via the examples below.

In your case, you should do:

g.V(event['securityEventManagerId']).values('sourceData').next()
like image 82
noam621 Avatar answered Feb 16 '23 14:02

noam621


Here's a snippet:

for p in g.V(v).properties():
   print("key:",p.label, "| value: " ,p.value)

where v is the vertex you want to inspect.

like image 28
Eddy Wong Avatar answered Feb 16 '23 13:02

Eddy Wong