Reputation: 33
I have a graph with 2 different vertex classes with some identical properties.
I need to:
g.addV("Item").
property("color", "green").
property("material", "wood").
property("shape", "round").
property("price", 1.2).
addV("Item").
property("color", "green").
property("material", "wood").
property("shape", "round").
property("price", .9).
addV("Item").
property("color", "green").
property("material", "wood").
property("shape", "square").
property("price", 5).
addV("Product").
property("color", "green").
property("material", "wood").next();
What I've tried so far is this
g.V().has("Item", "price", P.inside(0, 10)).
group().
by(project("c", "m").
by("color").by("material")). //\1
local(unfold().
project("color", "material","price","product")
.by(select(Column.keys).select("c"))
.by(select(Column.keys).select("m"))
.by(select(Column.values).unfold().values("price").mean())
.by(
V().hasLabel("Product"). //\2
has("material",P.eq(select(Column.keys).select("c"))).fold()));
I understand that at 2
the scope changes so select(Column.keys)
no longer refers to the group.
However, I'm at a loss how to get the value of the c
(and m
) key into the traversal at 2
Upvotes: 3
Views: 984
Reputation: 2856
So I tried to solve it with a slightly different approach.
Each group will have all the items and the products for the color and material combo
that way most of the work will be done on your first group
step:
g.V().coalesce(
hasLabel("Item").has("price", P.inside(0, 10)),
hasLabel("Product").has("color").has("material")
).group()
.by(project("c", "m").by("color").by("material"))
.unfold()
.where(select(values).unfold().hasLabel("Item"))
.project("color", "material","price","product")
.by(select(keys).select("c"))
.by(select(keys).select("m"))
.by(select(values).unfold().hasLabel("Item").values("price").mean())
.by(select(values).unfold().hasLabel("Product").fold())
Upvotes: 2