neo4j 如何正确使用这些CAL?

xyhw6mcr  于 2022-11-29  发布在  其他
关注(0)|答案(1)|浏览(183)

我在 LOAD CSV 之后使用了第一个 CALL 来拆分交易,第二个用于在两种类型的节点(Legal_EntityNatural_Person)之间创建关系。SYSTEM 节点是我对包含数字(关系的数字解释)和这些关系的文本之间的关联的指令的模拟。
关于是 Legal_EntityNatural_Person 的关系类型,我需要连接其他节点(例如,如果代码为100,则表示法律-法律连接,文本为“有一个部门"。如果代码为110,则表示法律-物理连接,文本为“创建”)。
现在,我需要发出一个请求,以确定要构建连接的节点类型,并相应地构建连接。
如果需要,我可以为使用的数据添加更多澄清信息。

:auto LOAD CSV WITH HEADERS FROM 'file:///CSVs/связи_фикс_все.csv' as row
call {
    with row

    match (legal:Legal_Entity {hid_party: row['first_related_hid']})
    match (sys:SYSTEM) 
    with sys, legal,
        row, 
        sys['type_' + tostring(row['id_relation_type'])] as relation_data, 
        sys[row['second_related_type']] as rel_type

        CALL {
            WITH rel_type, relation_data, row, legal
            WITH rel_type, relation_data, row, legal
            WHERE rel_type = 'Legal_Entity'
            match (legal_2:Legal_Entity {hid_party : row['second_related_hid']})
    
            CALL apoc.create.relationship(legal, relation_data[1], NULL, legal_2) YIELD rel1
            CALL apoc.create.relationship(legal_2, relation_data[3], NULL, legal) YIELD rel2
            return rel_type as rel_type_2

            UNION

            WITH rel_type, relation_data, row, legal
            WITH rel_type, relation_data, row, legal
            WHERE rel_type = 'Natural_Person'
            match (natural:Legal_Entity {hid_party : row['second_related_hid']})
    
            CALL apoc.create.relationship(legal, relation_data[1], NULL, natural) YIELD rel1
            CALL apoc.create.relationship(natural, relation_data[3], NULL, legal) YIELD rel2
            return rel_type as rel_type_2
    } return rel_type_2

} IN TRANSACTIONS of 10 rows
k3bvogb1

k3bvogb11#

当嵌套子查询时,它们的行为似乎很奇怪。如果要批量导入数据并去掉顶级子查询,可以简单地使用PERIODIC COMMIT

:auto USING PERIODIC COMMIT 10
LOAD CSV WITH HEADERS FROM 'file:///CSVs/связи_фикс_все.csv' as row
with row

MERGE (legal:Legal_Entity {hid_party: row['first_related_hid']})
MERGE (sys:SYSTEM) 
with sys, legal,
    row, 
    sys['type_' + tostring(row['id_relation_type'])] as relation_data, 
    sys[row['second_related_type']] as rel_type

    CALL {
        WITH rel_type, relation_data, row, legal
        WITH rel_type, relation_data, row, legal
        WHERE rel_type = 'Legal_Entity'
        match (legal_2:Legal_Entity {hid_party : row['second_related_hid']})

        CALL apoc.create.relationship(legal, relation_data[1], NULL, legal_2) YIELD rel AS rel1
        CALL apoc.create.relationship(legal_2, relation_data[3], NULL, legal) YIELD rel AS rel2
        return rel_type as rel_type_2

        UNION

        WITH rel_type, relation_data, row, legal
        WITH rel_type, relation_data, row, legal
        WHERE rel_type = 'Natural_Person'
        match (natural:Legal_Entity {hid_party : row['second_related_hid']})

        CALL apoc.create.relationship(legal, relation_data[1], NULL, natural) YIELD rel AS rel1
        CALL apoc.create.relationship(natural, relation_data[3], NULL, legal) YIELD rel AS rel2
        return rel_type as rel_type_2
}
RETURN distinct 'done'

相关问题