0
votes

Hello I am trying to make relationship between two column in my csv file I am loading csv file which has an relationship column and it looks like this

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

so I want to make relation between AGENTID and CUSTOMERID. the relationship code is

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;

This is for testing purpose, but I am getting bellow error Neo.ClientError.Statement.SemanticError: Cannot merge node using null property value for name

Moreover Recently I have tried this too

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

I am not getting error here but I am not getting relationship result

actually I have a feeling that I have missed something very silly point.Kindly help me to understand why I am getting this error. and help me to solve this problem. Thanks

2

2 Answers

1
votes

You are getting SemanticError for the first query because there is no value(null) for CUSTOMERID or AGENTID somewhere in your file and hence it's like you are trying to MERGE node on a null value. You need to check for null value before MERGE and skip MERGE for these. See below.

It's not recommended to use multiple MERGE in the single query. Only one MERGE is recommended in one query.

Suggest you separate your query into two and use your second to create relationships.

Load AGENTIDs:

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

Load CUSTOMERIDs:

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

Create relationships between AGENTIDs and CUSTOMERIDs:

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
0
votes

Thanks Raj for your answer. In my case it didn't work until i did some modifications. Here my new code:

1. Load AGENTIDs:

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. Load CUSTOMERIDs:

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. Create relationships between AGENTIDs and CUSTOMERIDs:

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

Actually @Raj already mentioned here "WHERE can not be used with MERGE."