我正在尝试将节点从csv文件动态上传到neo4j graphdb。所以我正在开发一个脚本。这是我的代码
def CreateNodes(filename,label):
print(filename,label)
print(type(filename),type(label))
path=nodesourcefolder+filename
print(path)
#filestring=nodesourcefolder+filename
if(isfile(path)==True):
print("valid")
#nodequery="""CALL apoc.periodic.iterate('CALL apoc.load.csv(%s) yield map as row return row','CREATE (p:%s) SET p = row', {batchSize:10000, iterateList:true, parallel:true})"""%(path,label)
nodequery="""CALL apoc.periodic.iterate('CALL apoc.load.csv("""+path+""") yield map as row return row','CREATE (p:"""+label+""") SET p = row', {batchSize:10000, iterateList:true, parallel:true})"""
print(nodequery)
return nodequery
query=CreateNodes("test.csv","myNode")
graphdriver.run(query)
查询变量为我提供值test.csv MyNode
放出
<class 'str'> <class 'str'>
/Users/kalyan.admin/NEO4J_HOME/import/test.csv
valid
CALL apoc.periodic.iterate('CALL apoc.load.csv(/Users/kalyan.admin/NEO4J_HOME/import/test.csv) yield map as row return row','CREATE (p:myNode) SET p = row', {batchSize:10000, iterateList:true, parallel:true})
当我要运行图driver.run(query)
我遇到了以下错误
**ProcedureCallFailed: Failed to invoke procedure `apoc.periodic.iterate`: Caused by: org.neo4j.cypher.internal.v3_5.util.SyntaxException: Invalid input 'U': expected '*' or '/' (line 1, column 44 (offset: 43))**
当我将文件名,标签名传递给Createnode函数时,我已经获得了字符串文件的路径名和标签值。但是我的图形驱动程序无法创建节点
请帮助我解决这个问题。我已经尝试了两个节点查询操作,其中之一现在已被注释掉,但是所有这些查询在运行Graphdriver后给我相同的结果
答案 0 :(得分:1)
密码查询中存在语法问题,文件路径应为字符串。
这无效:
CMake Error at CMakeLists.txt:8 (target_include_directories):
target_include_directories called with invalid arguments
这是(请注意路径周围的双引号):
CALL apoc.periodic.iterate(
'CALL apoc.load.csv(/Users/kalyan.admin/NEO4J_HOME/import/test.csv) yield map as row return row',
'CREATE (p:myNode) SET p = row',
{batchSize:10000, iterateList:true, parallel:true}
)