无法将其记录中包含空格的csv文件导入Neo4j图数据库

时间:2016-06-01 15:10:52

标签: neo4j graph-databases

我试图通过将csv文件导入neo4j来创建图形,但我的记录包含一些空格,因此neo4j不允许创建节点

我无法用图形数据库中的任何其他内容替换空白区域 我的代码

LOAD CSV WITH HEADERS FROM "https://s3.amazonaws.com/xyz/test.csv" AS db

merge (dbn:dbname {name: db.origin })
merge (dbs:dbschema {name: db.dest})
merge (dbo:dbobj {name: db.via})


create (dbn)-[:via]->(dbs)-[:to]->(dbo)
return dbn,dbs,dbo

csv文件数据是这样的,

origin dest via

ny     hk      la
ny     moscow  ft
ny     london
ny     mumbai  dubai

现在从ny到伦敦是直接所以没有“通过”

但是当我创建节点时,我需要一个空节点的节点,让它名为null

2 个答案:

答案 0 :(得分:0)

也许你可以忽略via列没有值的行?

LOAD CSV WITH HEADERS FROM "https://s3.amazonaws.com/xyz/test.csv" AS db
WITH db
WHERE db.via IS NOT NULL
merge (dbn:dbname {name: db.referencing_DB_Name })
merge (dbs:dbschema {name: db.referencing_schema})
merge (dbo:dbobj {name: db.referencing_object_name})
merge (dbd:dbrdb {name: db.referenced_database})
merge (dbrs:dbrdsch {name: db.referenced_schema})
merge (dbro:dbrdobj {name: db.referenced_object_name})

create (dbn)-[:referencing_schema]->(dbs)-[:referencing_object_name]->(dbo)-[:referenced_database]->(dbd)-[:referenced_schema]->(dbrs)-[:referenced_object_name]->(dbro)
return dbn,dbs,dbo,dbd,dbrs,dbro

答案 1 :(得分:0)

您可以使用coalesce() function来处理csv中的空值。 Coalesce计算传递给它的第一个非null参数,因此如果你想使用" emptyData"对于name节点的DBObj属性,如果它没有出现在csv文件中,只需执行以下操作:

LOAD CSV WITH HEADERS FROM "http://some.url.com/file.csv" AS row
MERGE (dbn:DBName {name: row.origin })
MERGE (dbs:DBSchema {name: row.dest})
MERGE (dbo:DBObj {name: coalesce(row.via, "emptyData")})
CREATE (dbn)-[:via]->(dbs)-[:to]->(dbo)
return dbn,dbs,dbo