Easiest Way to Get List Cardinality Properties As a List?

What is the easiest way to retrieve the vertex properties that have list cardinality back as a list in the traversal stream? The values() step seems to unfold the list. For example, using the "the crew" example graph. gremlin> g.V().valueMap() ==>[name:[marko],location:[san diego,santa cruz,brussels,santa fe]] ==>[name:[stephen],location:[centreville,dulles,purcellville]] ==>[name:[matthias],location:[bremen,baltimore,oakland,seattle]] ==>[name:[daniel],location:[spremberg,kaiserslautern,aachen]] ==>[name:[gremlin]] ==>[name:[tinkergraph]] I want something like the following: gremlin> g.V().valueMap("location").select(values).unfold() ==>[san diego,santa cruz,brussels,santa fe] ==>[centreville,dulles,purcellville] ==>[bremen,baltimore,oakland,seattle] ==>[spremberg,kaiserslautern,aachen] Is there a more direct way than valueMap().select(values).unfold()?
Solution:
after some reflection i sense that the question you are asking is actually the answer in the first place. i assume this is in relation to string/list functions, in which case use of valueMap() as you did and group() would be the the primary ways you'd end with a List where the former is the most likely one for the average case where you might want to do like:
g.V().valueMap().by(toUpper(local))
g.V().valueMap().by(toUpper(local))
but instead, as there is no local have to do:...
Jump to solution
2 Replies
spmallette
spmallette11mo ago
I think I'd prefer the following:
gremlin> g.V().hasLabel('person').map(values('location').fold())
==>[san diego,santa cruz,brussels,santa fe]
==>[centreville,dulles,purcellville]
==>[bremen,baltimore,oakland,seattle]
==>[spremberg,kaiserslautern,aachen]
gremlin> g.V().hasLabel('person').map(values('location').fold())
==>[san diego,santa cruz,brussels,santa fe]
==>[centreville,dulles,purcellville]
==>[bremen,baltimore,oakland,seattle]
==>[spremberg,kaiserslautern,aachen]
that would avoid the construction of the Map of properties first which you kinda throw away with select(values).
Solution
spmallette
spmallette10mo ago
after some reflection i sense that the question you are asking is actually the answer in the first place. i assume this is in relation to string/list functions, in which case use of valueMap() as you did and group() would be the the primary ways you'd end with a List where the former is the most likely one for the average case where you might want to do like:
g.V().valueMap().by(toUpper(local))
g.V().valueMap().by(toUpper(local))
but instead, as there is no local have to do:
g.V().valueMap().by(unfold().toUpper().fold())
g.V().valueMap().by(unfold().toUpper().fold())
seems there might be some decent case for local in addition to just consistency. cc/ @bechbd , @Yang Xia