我通过它们的属性过滤一些顶点,并用
project()
步骤映射它们。在结果中,我希望所有顶点至少具有一个与我的过滤器匹配的属性,以及匹配的属性数量。我已经尝试过 as()
和 select()
- 这给了我一个空值。 aggregate()
步返回一个数组,其中包含所有遍历器的所有匹配属性数量。所以现在我正在尝试 sack() 但这也让我'null'
这是我的简短查询:
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()
)
)
“foundProps”的结果是所有找到的顶点 0。为什么? 我已经验证了 count() 返回了正确的结果。
这就是我认为在这种情况下发生的事情。
在
filter
步骤中,它基本上会产生一个匿名遍历来执行过滤步骤,但是,该遍历永远不会退出过滤步骤,因此在其中进行的任何 sack
修改也将丢失。这类似于为什么在 sack
步骤中使用 sideEffect
不起作用。
这不同于
union
步骤(这是一种分支),其中在步骤内产生的遍历可能会退出它,并且它们的 sack
(如果有的话)将被保留。