How can I merge vertices, including their incoming/outgoing edges and their properties? I used this answer and it does almost exactly what I hoped for, but in case both vertices have the same property, only one of them gets to the resulting united vertex. I would like to get this property as a list, like what happens when adding a property to a vertex that already has such property.
example scenario:
g.V().has("author","book_id", 987).fold().
coalesce(unfold(),
addV("author").property("book_id", 987))
g.V().hasLabel("author").has("book_id",987).property("author_id",123)
g.V().has("author","book_id", 654).fold().
coalesce(unfold(),
addV("author").property("book_id", 654))
g.V().hasLabel("author").has("book_id",654).property("author_id",123)
After those 4 queries, we will get 2 vertices with author_id=123
.
Using this query (as suggested in the answer) to merge them:
g.V().has("author", "author_id", 123).fold().filter(count(local). is (gt(1))).unfold().
sideEffect(properties().group("p").by(key).by(value())).
sideEffect(outE().group("o").by(label).by(project("p", "iv").by(valueMap()).by(inV()).fold())).
sideEffect(inE().group("i").by(label).by(project("p", "ov").by(valueMap()).by(outV()).fold())).
sideEffect(drop()).
cap("p", "o", "i").as("poi").
addV("author").as("a").
sideEffect(
select("poi").select("p").unfold().as("kv").
select("a").property(select("kv").select(keys), select("kv").select(values))).
sideEffect(
select("poi").select("o").unfold().as("x").select(values).
unfold().addE(select("x").select(keys)).
from
(select("a")).to(select("iv"))).
sideEffect(
select("poi").select("i").unfold().as("x").select(values).
unfold().addE(select("x").select(keys)).
from
(select("ov")).to(select("a"))).iterate()
Will result in a single vertex as expected, but the valueMap shows it only has one of the book_id
s as a property:
{'book_id': [654], 'author_id': [123]}
How can I keep both? as in:
{'book_id': [654,987], 'author_id': [123]}