Reputation: 231
Im filtering some vertices via their properties and map them with a project()
step. In the result I want all vertices which have at least one property that matches my filter, and the amount of properties that matched. I already tried as()
with select()
- which got me a null value. The aggregate()
-step returned an array that contained all matching property amounts of all traversers. So now I am trying sack()
but this also gets me 'null'
This is my query in short form:
g.V(someId)
.project("child_label","other_child_label")
.by(
__.out()
.hasLabel("child_label")
.filter(
__.properties()
.filter(__.key().is(Text.contains("foo")))
.filter(__.value().is(Text.contains("bar")))
.fold()
.sack(assign).by(__.count())
.count()
.is(P.gt(0L))
)
.project("name","foundProps")
.by("name")
.by(__.sack())
.fold()
)
//exactly the same just with one more out-step
.by(
__.out()
.out()
.hasLabel("child_label")
.filter(
__.properties()
.filter(__.key().is(Text.contains("foo")))
.filter(__.value().is(Text.contains("bar")))
.fold()
.sack(assign).by(__.count())
.count()
.is(P.gt(0L))
)
.project("name","foundProps")
.by("name")
.by(__.sack())
.fold()
)
)
The result for "foundProps"
is for all found vertices 0. Why?
I already verified that count()
returns the correct result.
Upvotes: 0
Views: 121
Reputation: 14391
Here's what I think is going on in this case.
Inside the filter
step, it's going to essentially spawn an anonymous traversal to carry out the filtering steps, but, that traversal never exits the filter step, so any sack
modifications done within it will be lost also. This is similar to why using sack
inside a sideEffect
step does not work.
This is different to, say, a union
step (which is a kind of branch) where the traversals spawned inside the step may exit it and their sack
(if any) will be preserved.
Upvotes: 0