Neptune、Python、Gremlin:使用值数组更新图形顶点中的属性

2024-06-16 13:25:31 发布

您现在位置:Python中文网/ 问答频道 /正文

使用Amazon Neptune作为GraphDB,我试图更新一些顶点的属性,以包含一个值列表。来自此guide的基本小精灵示例:

// Add a list as a property value
g.V().has('code','AUS').property('places',out().values('code').fold())  

在以下方面失败:

{
  "requestId": "XXX",
  "detailedMessage": "Unsupported property value type: java.util.ArrayList",
  "code": "UnsupportedOperationException"
}

我还试图添加list修饰符

g.V().has('code','AUS').property(list, 'places',out().values('code').fold())

在以下方面失败:

{
  "requestId": "XXX",
  "detailedMessage": "list cardinality for vertex property is not supported",
  "code": "UnsupportedOperationException"
}

如果由于某种原因,python gremlin或Amazon Neptune风格不支持数组或列表作为属性值,我可以选择一个值,将这些值连接成一个字符串。我尝试使用各种选项:

g.V().has('code','AUS').property('places',out().values('code').fold(0) {a,b -> a + b.length()})

g.V().has('code','AUS').property('places',out().values('code')map {join(",",it.get().value('code'))})

但都没有起作用


Tags: amazon列表属性valuecodepropertyfoldout
1条回答
网友
1楼 · 发布于 2024-06-16 13:25:31

我认为您必须在单独的property步骤中插入每个值

像这样:

g.V().has('code', 'AUS').as('airport').
  out().values('code').as('code').select('airport').
  property(set, 'places', select('code'))

编辑:

我在AWS user guide中看到列表基数不受支持。因此,最接近的解决方案是使用set基数

Neptune supports set cardinality and single cardinality. If it isn't specified, set cardinality is selected. This means that if you set a property value, it adds a new value to the property, but only if it doesn't already appear in the set of values. This is the Gremlin enumeration value of Set. List is not supported. For more information about property cardinality, see the Vertex topic in the Gremlin JavaDoc.

示例:https://gremlify.com/9v

相关问题 更多 >