如何在 python gremlin 中检索顶点的 属性 值
How to retrieve a property value of a vertex in python gremlin
这可能很容易,但我真的很难解决这个问题。我使用 gremlin python lib 和 aws 海王星数据库。
我知道顶点id,我只想获取顶点属性之一的值(String类型python),并更新它。
我试过这样做:
print(g.V(event['securityEventManagerId']).values('sourceData'))
print(g.V(event['securityEventManagerId']).property('sourceData'))
print(g.V(event['securityEventManagerId']).property('sourceData').valueMap())
.....
但我只是打印了一些 python gremlin 对象,例如 GraphTraversal
,无法将值检索为 string
谁能帮帮我?
您必须使用终端步骤,否则您的查询将无法执行。
来自 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.
对于你的情况,你应该这样做:
g.V(event['securityEventManagerId']).values('sourceData').next()
这是一个片段:
for p in g.V(v).properties():
print("key:",p.label, "| value: " ,p.value)
其中 v 是您要检查的顶点。
这可能很容易,但我真的很难解决这个问题。我使用 gremlin python lib 和 aws 海王星数据库。 我知道顶点id,我只想获取顶点属性之一的值(String类型python),并更新它。
我试过这样做:
print(g.V(event['securityEventManagerId']).values('sourceData'))
print(g.V(event['securityEventManagerId']).property('sourceData'))
print(g.V(event['securityEventManagerId']).property('sourceData').valueMap())
.....
但我只是打印了一些 python gremlin 对象,例如 GraphTraversal
,无法将值检索为 string
谁能帮帮我?
您必须使用终端步骤,否则您的查询将无法执行。
来自 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.
对于你的情况,你应该这样做:
g.V(event['securityEventManagerId']).values('sourceData').next()
这是一个片段:
for p in g.V(v).properties():
print("key:",p.label, "| value: " ,p.value)
其中 v 是您要检查的顶点。