I am trying to use apoc.do.case to create some relationship, depending if a row in a file exist using the WITH after reading the CSV
However, it seems like the "row" cannot be passed into the case
My attempt:
LOAD CSV WITH HEADERS FROM 'url' AS row
MERGE (i:Investor {Name: row.Investor_Name})
MERGE (ir:Investment_Round {id: row.Deal_ID})
WITH row, i, ir
CALL apoc.do.case([
row.Funds_Used IS NULL,
'MERGE (i)-[r:INVESTED_IN]->(ir) SET r.Investment_Size_million_GBP=toFloat(row.Investment_Size_million_GBP), r.Investment_Size_million_EUR=toFloat(row.Investment_Size_million_EUR)',
row.Funds_Used IS NOT NULL, 'MERGE (f:Fund {Name: row.Funds_Used}) WITH row, f, i, ir MERGE (i)-[r:HAS_FUND]->(f) MERGE (f)-[r2:INVESTED_IN]->(ir) SET r2.Investment_Size_million_GBP = row.Investment_Size_million_GBP, r2.Investment_Size_million_EUR = row.Investment_Size_million_EUR;'])
YIELD value RETURN value;
The error:
Failed to invoke procedure `apoc.do.case`: Caused by: org.neo4j.exceptions.SyntaxException: Variable `row` not defined (line 1, column 75 (offset: 74))
"MERGE (i)-[r:INVESTED_IN]->(ir) SET r.Investment_Size_million_GBP=toFloat(row.Investment_Size_million_GBP), r.Investment_Size_million_EUR=toFloat(row.Investment_Size_million_EUR)"
>Solution :
You are not passing the row variable as a parameter. Try this:
LOAD CSV WITH HEADERS FROM 'url' AS row
MERGE (i:Investor {Name: row.Investor_Name})
MERGE (ir:Investment_Round {id: row.Deal_ID})
WITH row, i, ir
CALL apoc.do.case([
row.Funds_Used IS NULL,
'MERGE (i)-[r:INVESTED_IN]->(ir)
SET r.Investment_Size_million_GBP=toFloat(row.Investment_Size_million_GBP), r.Investment_Size_million_EUR=toFloat(row.Investment_Size_million_EUR)',
row.Funds_Used IS NOT NULL,
'MERGE (f:Fund {Name: row.Funds_Used}) WITH row, f, i, ir MERGE (i)-[r:HAS_FUND]->(f) MERGE (f)-[r2:INVESTED_IN]->(ir) SET r2.Investment_Size_million_GBP = row.Investment_Size_million_GBP, r2.Investment_Size_million_EUR = row.Investment_Size_million_EUR;'],
'',
{row: row, i: i, ir: ir}) // The parameters are passed here
YIELD value RETURN value;