0

My data looks like this:

predecessor,successor
AAMBD01P.ACCOUNT_ANALYTICAL_BALANCE,DIMS32P.NHJ_DEPOSIT
AAMBD01P.CUSTOMER_ACCOUNT_REL,DIMS32P.NHJ_DEPOSIT
AAMBD01P.CUSTOMER_SUB_DETAIL2_BBKKA,DIMS32P.NHJ_DEPOSIT
AAMBD01P.CUSTOMER_BBKKA_DETAIL,DIMS32P.NHJ_DEPOSIT
AAMBD08P.CUSTOMER_DETAIL2_FULL,DIMS32P.NHJ_DEPOSIT
AAMBD08P.ACC_CURR_DEP_STAT_HIST,DIMS32P.NHJ_DEPOSIT
MISV19P.V_CUSTOMER_SEGM,DIMS32P.NHJ_DEPOSIT

I'm trying to load it into my Neo4J instance but I get this error:

neo4j.exceptions.CypherSyntaxError: {code: Neo.ClientError.Statement.SyntaxError} {message: Query cannot conclude with LOAD CSV (must be RETURN or an update clause) (line 1, column 1 (offset: 0))
"LOAD CSV WITH HEADERS FROM 'file:///data.csv' AS line"
 ^}

My code:

from neo4j import GraphDatabase

driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "187179"))

def add_data(tx):
    tx.run("LOAD CSV WITH HEADERS FROM 'file:///data.csv' AS line")
    tx.run("MERGE (s:src {id: line.source})")
    tx.run("MERGE (d:dst {id: line.destination})")
    tx.run("CREATE (s)-[:FEEDs_INTO]->(d)")

with driver.session() as session:
    session.write_transaction(add_data)
driver.close()
neekitit
  • 61
  • 6

1 Answers1

1

You are trying to run a single query in 4 parts. The tx.run() requires complete query.

You can modify your code as:

def add_data(tx):
    tx.run("LOAD CSV WITH HEADERS FROM 'file:///data.csv' AS line \
           MERGE (s:src {id: line.source}) \
           MERGE (d:dst {id: line.destination}) \
           CREATE (s)-[:FEEDs_INTO]->(d)")
Rajendra Kadam
  • 4,004
  • 1
  • 10
  • 24
  • Yeah, you're right. Now i get this error: neo4j.exceptions.ClientError: {code: Neo.ClientError.Statement.ExternalResourceFailed} {message: Couldn't load the external resource at: file:/C:/Users/Damian/.Neo4jDesktop/relate-data/dbmss/dbms-fc8f1ea1-d31e-4761-99ae-319cb3dd634e/import/data.csv} . Do you maybe know how to solve it ? – neekitit Oct 14 '21 at 12:47
  • There are multiple reasons like your CSV is not formatted correctly, or Your Neo4j is not configured to load the external files. Could you please check the following answer if it doesn't work then check file format: https://stackoverflow.com/a/56573777/6077914 – Rajendra Kadam Oct 14 '21 at 14:17
  • 1
    I found the reason. It was because I had to give absolute path to the file. Now it's ok. – neekitit Oct 14 '21 at 15:05