java - 如何在嵌套的 Gremlin 遍历中引用 as-variable?
问题描述
尝试编写仅在从顶点 Vo 到顶点 Vi 不存在边时才匹配的遍历(其中 Vi 的 ID 可能无法提前知道,因此必须通过遍历指定 Vi)。
我有这个初始遍历:
<A> GraphTraversal<A, Edge> addEdge(
GraphTraversal<A, Vertex> traversalToVo,
String viSelectKey
) {
return traversalToVo.coalesce(
__.outE("Manages").and(
__.inV().as("inV").where("inV", P.neq(viSelectKey))
// more conditions
),
__addE("Manages").to(select(viSelectKey))
);
}
我的问题是我不知道如何Vi
在嵌套的匿名遍历中使用;我想到的一切都会导致错误
Neither the sideEffects, map, nor path has a Vi-key: WherePredicateStep(inV,neq(Vi))
我已经调试了对 的调用getScopeValue
,实际上Vi
当我到达那里时从未定义过。
我尝试填充的方法Vi
包括:
// define "Vi" in the upstream part of the query
gts.addV(...).as("Vi").V(Vo).coalesce(...)
// modeled after "Long Traversals" recipe; variable not defined afterward
gt.V(Vo).sideEffect(viTraversal.asAdmin().clone().as("Vi")).coalesce(...)
// produces a Map, and I can't apply unfold() downstream inside predicate
gt.sideEffect(viTraversal.asAdmin().clone().group("Vi"))
据我所知,这是一些将嵌套匿名遍历与范围值分离的范围规则的结果;如何弥合差距,以便as
可以从内部合并和何处引用遍历上游部分中定义的变量?
解决方案
这种方法似乎效率低下且令人讨厌,但确实有效。我仍然不知道为什么我可以访问 agroup
但不能访问as
.
traversalToVo.sideEffect(traversalToVi.asAdmin().clone().group("toV").by(id))
.coalesce(
__.outE("rel").and(
__.inV().id().where(P.within("toV")).by().by(Column.keys),
// other filters
),
__.addE("rel").to(traversalToVi)
)
推荐阅读
- java - 来自 2 个不同的记录器线程的重复日志语句
- ios - 如何将 @react-native-community/datetimepicker 中的 pod 'RNDateTimePicker' 添加到我的 NPM 项目中,以便在用户安装包时安装它?
- arrays - C: 结构数组上的 qsort() -- 返回垃圾
- numpy - ImportError: numpy.core.multiarray 导入失败 (2021)
- python - Python 插件架构,其中插件是包
- cplex - Pyomo 关闭 cplex 的 presolve
- function - 设定时间后停止功能
- authentication - 隐式流现在比授权码流更流行吗?
- pytorch - 如何量化以 GRUCell 作为子模块的模块
- powermock - 使用 powermock 和 jbehaves 时遇到问题