我有一个与部门雇员一起工作的常见情景:
MY_PARENT_IS
relation 特定员工的经理可以是:
IS_SPECIFIED_LEADER_FOR
IN_CHARGE_PERSON
的第一个人(我们从给定员工上升结构,直到找到设置了IN_CHARGE_PERSON
关系的部门。)示例结构:
为实现这一目标,我有2个问题:
第一个获取指定领导者的查询:
SELECT expand(manager) FROM (MATCH {class:HRUnitPersonCompany,
where: (Name = 'Sales Berseker 1' AND in('IS_SPECIFIED_LEADER_FOR').size() > 0)}.in('IS_SPECIFIED_LEADER_FOR')
{as: manager} RETURN manager)
第二个查询找到结构的第一个经理(IN_CHARGE_PERSON
)
SELECT expand(manager) FROM (MATCH {class:HRUnitPersonCompany,
where: (Name = 'Sales Berseker 1')}.out('MY_PARENT_IS')
{while: (out('IN_CHARGE_PERSON').size() == 0),
where: (out('IN_CHARGE_PERSON').size() > 0)}.out('IN_CHARGE_PERSON')
{as: manager} RETURN manager)
问题是如何将这两个查询合并为一个语句,该语句将返回第一个或第二个的结果,但仅在第一个没有返回结果的情况下?
我玩LET但是不能100%工作(这会转换查询解析错误):
SELECT if($specMgr.size()>0,$specMgr,$depMgr)
LET $specMgr = (SELECT expand(manager) FROM (MATCH {class:HRUnitPersonCompany,
where: (Name = 'Sales Berseker 1' AND in('IS_SPECIFIED_LEADER_FOR').size() > 0)}.in('IS_SPECIFIED_LEADER_FOR')
{as: manager} RETURN manager)),
$depMgr = (SELECT expand(manager) FROM (MATCH {class:HRUnitPersonCompany,
where: (Name = 'Sales Berseker 1')}.out('MY_PARENT_IS')
{while: (out('IN_CHARGE_PERSON').size() == 0),
where: (out('IN_CHARGE_PERSON').size() > 0)}.out('IN_CHARGE_PERSON')
{as: manager} RETURN manager))
问题在于条件,当我删除比较时,至少没有报告错误但是它没有按预期工作。为什么我不能在if语句中使用.size() > 0
比较?
答案 0 :(得分:0)
好的,解决了,原来我错过了eval()并没有读到eval的内容必须放在引号之间。 工作查询如下:
SELECT EXPAND(if(eval('$specMgr.size() > 0'),$specMgr,$depMgr))
LET $specMgr = (SELECT expand(manager) FROM (MATCH {class:HRUnitPersonCompany,
where: (Name = 'Sales Berseker 1' AND in('IS_SPECIFIED_LEADER_FOR').size() > 0)}.in('IS_SPECIFIED_LEADER_FOR')
{as: manager} RETURN manager)),
$depMgr = (SELECT expand(manager) FROM (MATCH {class:HRUnitPersonCompany,
where: (Name = 'Sales Berseker 1')}.out('MY_PARENT_IS')
{while: (out('IN_CHARGE_PERSON').size() == 0),
where: (out('IN_CHARGE_PERSON').size() > 0)}.out('IN_CHARGE_PERSON')
{as: manager} RETURN manager))