I am trying to write a python script for uploading csv files into graphdb with apoc procedure call. I am trying to make it dynamic. So I have a function name CreateNodes(filename, label) which takes a csvfile and node label for creating NODE in graphdb for given query
My code is given below
def CreateNodes(filename,label):
print(filename,label)
print(type(filename),type(label))
nodequery="""CALL apoc.periodic.iterate('CALL apoc.load.csv(filename) yield map as row return row','CREATE (p:label) SET p = row', {batchSize:10000, iterateList:true, parallel:true})"""
return nodequery
query=CreateNodes("test.csv","NODE1")
I have checked my function and filename and label parameter takes the passing value
query=CreateNodes("test.csv","NODE1")
test.csv NODE1
<class 'str'> <class 'str'>
but when I am going to run graphdriver.run(query) for creating node in graphdb
graphdriver.run(query)
I am getting below error
ClientError: ProcedureCallFailed: Failed to invoke procedure 'apoc.periodic.iterate': Caused by: org.neo4j.cypher.internal.v3_5.util.SyntaxException: Variable 'filename' not defined (line 1, column 43 (offset: 42))
maybe I am missing something in query. In fact I have also tried explicit filename.csv in my apoc query then it worked. but I want to pass the filename and label variable inside cypher query for getting result
I am using py2neo python driver for neo4j, and my neo4j version is 3.5.6 and my apoc procedure library version is 3.5.0.4