获取Neo.ClientError.Statement.SemanticError:无法使用空属性合并节点

时间:2019-06-22 21:13:07

标签: neo4j cypher neo4j-apoc

您好,我正在尝试在csv文件中的两列之间建立关系 我正在加载具有关系列的csv文件,看起来像这样

RELATIONSHIP,AGENTID,CUSTOMERID,TXNID,TIMESTAMP,AMOUNT,CHANNEL
hasrelation,17956,2025,6C13MXSESN,2019-03-01T11:52:08,10,USSD
hasrelation,17957,2026,6C13MXSEVF,2019-03-01T11:52:09,50,BAPP

所以我想在AGENTID和CUSTOMERID之间建立联系。关系代码是

load csv with headers from "file:///test.csv" AS row
MERGE (p1:AGENTID {name: row.AGENTID})
MERGE (p2:CUSTOMERID {name: row.CUSTOMERID})
WITH p1, p2, row
CALL apoc.create.relationship(p1, row.relationship, {}, p2) YIELD rel
RETURN rel;

这是出于测试目的,但出现以下错误 Neo.ClientError.Statement.SemanticError:无法使用名称的空属性值合并节点

而且最近我也尝试过

LOAD CSV WITH HEADERS FROM "file:///test.csv" AS row
MATCH (f:AGENTID), (s:CUSTOMERID)
WHERE f.Name = row.AGENTID
AND s.Name = row.CUSTOMERID
CALL apoc.create.relationship(f, row.RELATIONSHIP,{}, s) YIELD rel
RETURN rel

我在这里没有收到错误,但没有得到联系结果

实际上我感觉自己错过了一些非常愚蠢的问题。请帮助我理解为什么会出现此错误。并帮助我解决这个问题。谢谢

2 个答案:

答案 0 :(得分:1)

您的第一个查询得到SemanticError,因为文件中某处没有CUSTOMERIDAGENTID的值(空),因此就好像您要尝试{{1 }}节点放在MERGE值上。您需要在null之前检查null值,并跳过MERGE。见下文。

不建议在单个查询中使用多个MERGE在一个查询中仅建议一个MERGE

建议您将查询一分为二,然后使用第二个查询来创建关系。

加载AGENTID:

MERGE

加载客户ID:

LOAD CSV WITH HEADERS FROM "file:///test.csv" AS row
WHERE row.AGENTID IS NOT NULL
MERGE (p1:AGENTID {name: row.AGENTID});

在AGENTID和CUSTOMERID之间创建关系:

LOAD CSV WITH HEADERS FROM "file:///test.csv" AS row
WHERE row.CUSTOMERID IS NOT NULL
MERGE (p2:CUSTOMERID {name: row.CUSTOMERID})

答案 1 :(得分:0)

感谢Raj的回答。就我而言,直到我做了一些修改,它才起作用。这是我的新代码:

1。加载AGENTID:

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///test.csv" AS row
WITH row
WHERE row.AGENTID IS NOT NULL
MERGE (p1:AGENTID {name: row.AGENTID});

2。加载客户编号:

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///test.csv" AS row
WITH row
WHERE row.CUSTOMERID IS NOT NULL
MERGE (p2:CUSTOMERID {name: row.CUSTOMERID})

3。在AGENTID和CUSTOMERID之间创建关系:

LOAD CSV WITH HEADERS FROM "file:///test.csv" AS row
MATCH (f:AGENTID), (s:CUSTOMERID)
WHERE f.name = row.AGENTID
AND s.name = row.CUSTOMERID
CALL apoc.create.relationship(f, row.RELATIONSHIP,{}, s) YIELD rel
RETURN rel

实际上@Raj已经提到here “无法在MERGE中使用。”