无法有条件地过滤Gremlin查询结果



我有Gremlin查询,我需要在最后过滤结果。员工id、技能名称和日期作为参数传递。如果该员工具有该技能,则只返回该员工id,否则,如果有其他员工向同一经理报告并具有该特定技能,则返回其员工id。

因此,如果传递了雇员id 2和c++作为技能,则查询将只返回雇员id 2,尽管雇员id 4也具有相同的技能。

如果员工id 2和Python作为技能通过员工id 2没有Python技能传递,它将返回员工id 1和4,因为他们向同一个经理报告。

我无法过滤最终结果。我试图检查传递的员工id是否存在于结果中,然后只返回该员工id,否则返回整个结果。

我正在从员工节点遍历到经理节点,然后找出所有向同一经理报告并具有与传递参数相同技能的其他员工。我需要遍历到管理器节点,因为我需要基于管理器的属性实现一些其他检查。

我的样本数据可以在这里找到https://gremlify.com/877vu2x3dfv

g.V().
has('emp', 'emp_id', 2).as('empview').
outE().
hasLabel('emp-desig').
has('start_date', lte(1643702400)).
has('end_date', gte(1643702400)).
select('empview').
outE().
hasLabel('emp-mgr').
has('start_date', lte(1643702400)).
has('end_date', gte(1643702400)).
otherV().
inE().
hasLabel('emp-mgr').
otherV().as('empidview').
outE().
hasLabel('emp-skill').
otherV().
has('skill_name', 'C++').
select('empidview').
coalesce(
where(values('emp_id').is(eq(2))),
where(values('emp_id').is(eq(2))),
where(values('emp_id').is(neq(2)))).
valueMap()

我正在使用AWS海王星数据库。我的实际查询将用gremlin python

编写

我认为这是你想要的:

g.V().has("emp","emp_id", 2).
filter(outE().
has('emp-desig','start_date', lte(1643702400)).
has('end_date', gte(1643702400))).as('emp')
coalesce(filter(out("emp-skill").has("skill", "skill_name", "Python")),
outE("emp-mgr").
has('start_date', lte(1643702400)).
has('end_date', gte(1643702400)).
inV().
in("emp-mgr").
where(is(neq("emp")))
filter(out("emp-skill").has("skill", "skill_name", "Python")))

我一直在寻找方法来消除as()/select()模式的过度使用。回溯会使查询更难阅读,并可能导致性能下降。我所采用的方法应该读起来更清楚,因为您找到给定某些标准的员工,然后有一个简单的if-then,其中员工具有技能并返回,否则,您将遍历经理以获得不同的标准。

最新更新