我正在使用LOAD CSV导入节点和关系,但其中一列是" country_id"我用来创建与另一个的关系在输入数据集中有时不是NULL,只有当列具有值时才会如何进行条件MERGE。我试过" CASE"但它不适用于" IS NOT NULL"。
谢谢。
路易斯奥斯卡
以下是我的代码,目前为country_id删除NULL' s:
USING PERIODIC COMMIT 20
LOAD CSV WITH HEADERS FROM 'file:///physical_location.csv' as row
WITH
toInt(row.physical_location_id) as physical_location_id,
CASE row.country_id WHEN IS NOT NULL THEN MERGE (c:Country {code:country_id}) END,
toFloat(row.latitude) as latitude,
toFloat(row.longitude) as longitude,
row.addressline1 as addressline1,
row.addressline2 as addressline2,
row.cityname as cityname,
row.postalcode as postalcode,
row.telephone as telephone,
row.airport as airport,
row.railway as railway,
row.ferryport as ferryport,
row.iata_airport_code as iata_airport_code,
row.iata_city_code as iata_city_code,
row.timezone as timezone,
row.pickup_only as pickup_only,
row.return_only as return_only,
row.outofhours_return as outofhours_return,
row.dropbox as dropbox,
row.delivery_collection as delivery_collection,
row.pl_email as pl_email
//where country_id IS NOT NULL
MERGE (pl:PhysicalLocation {physical_location_id:physical_location_id})
ON MATCH SET
pl.addressline1 = addressline1,
pl.addressline2 = addressline2,
pl.cityname = cityname,
pl.postalcode = postalcode,
pl.telephone = telephone,
pl.airport = airport,
pl.railway = railway,
pl.ferryport = ferryport,
pl.iata_airport_code = iata_airport_code,
pl.iata_city_code = iata_city_code,
pl.timezone = timezone,
pl.pickup_only = pickup_only,
pl.return_only = return_only,
pl.outofhours_return = outofhours_return,
pl.dropbox = dropbox,
pl.delivery_collection = delivery_collection,
pl.pl_email = pl_email
//MERGE (pl)-[r:IN_COUNTRY]->(c)
RETURN count(pl)
答案 0 :(得分:3)
如果coalesce
为空,则可以使用密码country_id
函数设置默认值:MERGE (c:Country {code:coalesce(row.country_id, 'NULL')})
在您的LOAD CSV完成后,您可以进行清理查询以删除您的默认国家/地区:DETACH DELETE (c:Country code:'NULL'});