从csv文件中读取数据并设置为忽略空值的动态属性

时间:2017-05-10 14:30:14

标签: neo4j cypher neo4j-apoc

我正在尝试从csv文件中读取数据,并将它们设置为Neo4J数据库中现有节点的动态属性。我正在使用setProperty程序,因为我不知道数据(属性的名称和值)。这是我的Cypher脚本:

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:\\Attribute.csv" AS row
MATCH (linkableArtifact:LinkableArtifact {linkableArtifactID: row.linkable_artifact})
CALL apoc.create.setProperty(linkableArtifact, row.attribute_name, row.attribute_value)
YIELD node
RETURN COUNT(node)

这可用,因为row.attribute_value长不为空。然后我收到以下错误:

Failed to call procedure `apoc.create.setProperty(nodes :: ANY?, key :: STRING?, value :: ANY?) :: (node :: NODE?)`: [null] is not a supported property value

有没有办法检查row.attribute_value然后决定是否调用该程序?

1 个答案:

答案 0 :(得分:0)

Cipher是一种声明性语言,因此很容易row.attribute_value is not NULL

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:\\Attribute.csv" AS row
WITH row WHERE row.attribute_value is not NULL
MATCH (artifact:LinkableArtifact {linkableArtifactID: row.linkable_artifact})
CALL apoc.create.setProperty(artifact, 
                             row.attribute_name, 
                             row.attribute_value
)
YIELD node
RETURN COUNT(node)