Add a collection of values in an edge property
Hi, I tried to find out some Gremlin example but nothing.
Is it possible add, in a single edge property a collection (like a list) of values?
For instance:
g.addE('link').from('x').to('y').property('p', [1, 2, 4]).next()Then I should be able to traverse, using one of the values contained in the list 1, 2, or 4. The only way to overtake that, I creted multiple edges, each with the property value from the list 1, 2 or 4. But I should create only one edge with the list.
9 Replies
Currently TinkerPop does not define support for multi-properties (set/list cardinality) on Edges. Depending on the graph, you can sometimes store a literal list as an edge property (for example TinkerGraph allows it) but what you are storing there is really a Java list object at that point.
To manipulate such a property you will end up either accessing it using
local
scope, or regularly needing to unfold
it.@kelvinl2816 thanks for replying.
When you say a literal list, do you mean, a list in a string like:
... property('p', '[1, 2, 3]') ...Other thing, these list attributes, on the edges, will be static, in the sense that, they will not change at all. Once the list of attributes are loaded, on each edge, when the graph is created, they will not be changed. They will be used during traverse queries.
I meant an actual list object such as
[1,2,3,4]
that didn't work:
gremlin> g.addE('link').from(n1).to(n2).property('color', ["att1", "att2"]).next() Property value [[att1, att2]] is of type class java.util.ArrayList is not supported
I thought that worked with JanusGraph but maybe it does not. It's definitely not supported by all TinkerPop enabled graph databases. Perhaps it only works for vertices with JanusGraph.
Can you please paste the stack trace you are getting with this error message?
I'm wondering whether this is a variation of the problem described in this issue: https://issues.apache.org/jira/browse/TINKERPOP-2186
Hi @Florian Hockmann, you can find attached.
Have you tried the workaround mentioned by @spmallette in the linked JIRA issue?
Hey Florian, it worked, thanks. I could see the edge with the list of values. However, I am trying now traverse this graph in a such way:
1. the edge can possible be one of the list values
For instance, assuming that:
n1, n2 and n3 are nodes n1 -> n2 (edge property 'x' is ['a1', 'a2']) n1 -> n3 (edge property 'x' is ['a1', 'a'3])I should be able to traverse like that:
g.V().has(n1....has('x', "a1").iterate().values('id') ==> n2 ==> n3because each edges, to n2 and to n3, has inside of the list 'a1'. Otherwise if I do:
g.V().has(n1....has('x', "a2").iterate().values('id') ===> n2I was wondering if I could work with some lambda to achieve that?