我通过csv import(py2neo批量导入)填充Neo4j。我想通过使用从csv文件生成的现有节点来创建关系。在我当前的csv文件中," sheet_name"列列出了现有csv文件的名称和" row_name"列显示从相关csv文件生成的节点。
for row in reader:
if row:
name = strip(row[0])
created_by = strip(row[1])
barcode = strip(row[3])
sheet_name = strip(row[4])
row_name = strip(row[5])
query = """
merge (document:Document {name:{a}})
merge (sheet_name:Sheet_Name {sheet_name:{b}})
merge (to_deliver:To_Deliver {row_name:{c}}) #This node was created before from other csv file
merge (delivered_Delivered {row_name:{c}}) #This node was created before from other csv file
CASE WHEN sheet_name.value = 'Pending' THEN MERGE (document)-[:STATUS_IS]->(to_deliver)
CASE WHEN sheet_name.value = 'Completed' THEN MERGE (document)-[:STATUS_IS]->(delivered)
"""
batch.append(query, {"a": name, "b": created_by, "c": barcode,
"d": sheet_name, "e": row_name})
i += 1
j += 1
batch.process()
我想基于
创建关系- 如果" sheet_name"的值待处理,然后文档状态为" to_deliver" - 和;
- 如果" sheet_name"的值已完成,然后文档状态已发送" -
" to_deliver"并且"交付"从其他csv文件创建节点之前。当我运行代码时,我得到一个错误,如Invalid input 'A': expected 'r/R'
CASE..THEN是否适合条件语句?感谢
答案 0 :(得分:1)
在Cypher中进行条件写操作有点棘手。您可以将FOREACH
与CASE WHEN
结合使用来迭代1个元素数组,并在条件为真时执行操作。
这个概念在http://www.markhneedham.com/blog/2014/06/17/neo4j-load-csv-handling-conditionals/得到了很好的解释。