Что я делаю, как показано ниже.1-й apoc.do.when счастливо использует строковую переменную, но когда шифр достигает (WITH value.r AS r, строка), я получаю взломанный код с ошибкой Neo.ClientError.Statement.SyntaxError: Строка переменной не определена
Выполнение Cypher завершается с ошибкой Neo.ClientError.Statement.SyntaxError: Строка переменной не определена (строка 12, столбец 20 (смещение: 469)) «WITH value.r AS r, строка» ^
LOAD CSV WITH HEADERS FROM "file:///the-file-name.csv" as
line FIELDTERMINATOR ','
with line as line
OPTIONAL MATCH (n:Region)
WHERE n.region contains "BLANKEMPTYVIDE" AND n.identifier= line.CODE_TER
with n
CALL apoc.do.when(
n IS NULL,
'MERGE (r:Region{region: line.TERRITOIRE}) ON CREATE SET r.description=line.TERRITOIRE ON CREATE SET r.identifier=line.CODE_TER ON CREATE SET r.id = toString(id(r)) RETURN r',
'RETURN n AS r',
{}) YIELD value
WITH value.r AS r, line
SET r.identifier=line.CODE_TER
SET r.description=line.TERRITOIRE
SET r.region=line.TERRITOIRE
WITH r,line
OPTIONAL MATCH (ci:City) where ci.cityName contains "BLANKEMPTYVIDE" AND ci.regionIdentifier= line.CODE_TER
CALL apoc.do.when(
ci IS NULL,
'MERGE (c:City {cityName:line.BRICK}) ON CREATE SET c.identifier=line.CODE_BRICK ON CREATE SET c.region=line.TERRITOIRE ON CREATE SET c.regionIdentifier=line.CODE_TER ON CREATE SET c.zip=line.CODE_BRICK ON CREATE SET c.description=line.BRICK ON CREATE SET c.id = toString(id(c)) RETURN c',
'RETURN ci AS c',
{}) YIELD value
WITH value.c AS c,line,r
SET c.identifier=line.CODE_BRICK
SET c.region=line.TERRITOIRE
SET c.regionIdentifier=line.CODE_TER
SET c.zip=line.CODE_BRICK
SET c.description=line.BRICK
SET c.cityName=line.BRICK
WITH c,r,line
MATCH (c {identifier:line.CODE_BRICK}),(r {identifier:line.CODE_TER})
MERGE (c)-[:IS_A_City_BELONGING_TO]->(r)
WITH c,r,line
OPTIONAL MATCH (sec:Sector)
WHERE sec.description contains "BLANKEMPTYVIDE" AND sec.regionIdentifier=line.CODE_TER
CALL apoc.do.when(
sec IS NULL,
'MERGE (s:Sector {sectorName:line.SOUSBRICK}) ON CREATE SET s.identifier=line.CODE_SBRICK ON CREATE SET s.region=line.TERRITOIRE ON CREATE SET s.regionIdentifier=line.CODE_TER ON CREATE SET s.city=line.BRICK ON CREATE SET s.cityIdentifier=line.CODE_BRICK ON CREATE SET s.description=line.SOUSBRICK ON CREATE SET s.zip=line.SOUSBRICK ON CREATE SET s.id = toString(id(s)) RETURN s',
'RETURN sec AS s',
{}) YIELD value
WITH value.s AS s,line,c,r
SET s.identifier=line.CODE_SBRICK
SET s.region=line.TERRITOIRE
SET s.regionIdentifier=line.CODE_TER
SET s.city=line.BRICK
SET s.cityIdentifier=line.CODE_BRICK
SET s.description=line.SOUSBRICK
SET s.zip=line.SOUSBRICK
SET s.sectorName = line.SOUSBRICK
WITH s,c,r,line
MATCH (s {identifier:line.CODE_SBRICK}),(r{identifier:line.CODE_TER})
MERGE (s)-[:IS_A_SECTOR_BELONGING_TO_THAT_REGION]->(r)
WITH s,c,r,line
MATCH (s {identifier:line.CODE_SBRICK}),(c{identifier:line.CODE_BRICK})
MERGE (s)-[:IS_A_SECTOR_BELONGING_TO_THAT_CITY]->(c)
the-file-name.csv находится на предыдущем вопросе Как сделать запрос Cypher для обработки обоих случаев без дублирования узлов
Здесь я поставил обновлениепо совету киберсама и Дэйва Большое спасибо вам обоим.
LOAD CSV WITH HEADERS FROM "file:///the-file-name.csv" as line
FIELDTERMINATOR ','
with line as line
OPTIONAL MATCH (n:Region)
WHERE n.region contains "BLANKEMPTYVIDE" AND n.identifier= line.CODE_TER
WITH n, line
CALL apoc.do.when(
n IS NULL,
'MERGE (r:Region{region: line.TERRITOIRE}) ON CREATE SET r.description=line.TERRITOIRE ON CREATE SET r.identifier=line.CODE_TER ON CREATE SET r.id = toString(id(r)) RETURN r',
'RETURN n AS r',
{n: n, line: line}) YIELD value
WITH value.r AS r, line
SET r.identifier=line.CODE_TER
SET r.description=line.TERRITOIRE
SET r.region=line.TERRITOIRE
WITH r,line
OPTIONAL MATCH (ci:City) where ci.cityName contains "BLANKEMPTYVIDE" AND ci.regionIdentifier= line.CODE_TER
CALL apoc.do.when(
ci IS NULL,
'MERGE (c:City {cityName:line.BRICK}) ON CREATE SET c.identifier=line.CODE_BRICK ON CREATE SET c.region=line.TERRITOIRE ON CREATE SET c.regionIdentifier=line.CODE_TER ON CREATE SET c.zip=line.CODE_BRICK ON CREATE SET c.description=line.BRICK ON CREATE SET c.id = toString(id(c)) RETURN c',
'RETURN ci AS c',
{ci: ci, line: line}) YIELD value
WITH value.c AS c,line,r
SET c.identifier=line.CODE_BRICK
SET c.region=line.TERRITOIRE
SET c.regionIdentifier=line.CODE_TER
SET c.zip=line.CODE_BRICK
SET c.description=line.BRICK
SET c.cityName=line.BRICK
WITH c,r,line
MATCH (c {identifier:line.CODE_BRICK}),(r {identifier:line.CODE_TER})
MERGE (c)-[:IS_A_City_BELONGING_TO]->(r)
WITH c,r,line
OPTIONAL MATCH (sec:Sector)
WHERE sec.description contains "BLANKEMPTYVIDE" AND sec.regionIdentifier=line.CODE_TER
CALL apoc.do.when(
sec IS NULL,
'MERGE (s:Sector {sectorName:line.SOUSBRICK}) ON CREATE SET s.identifier=line.CODE_SBRICK ON CREATE SET s.region=line.TERRITOIRE ON CREATE SET s.regionIdentifier=line.CODE_TER ON CREATE SET s.city=line.BRICK ON CREATE SET s.cityIdentifier=line.CODE_BRICK ON CREATE SET s.description=line.SOUSBRICK ON CREATE SET s.zip=line.SOUSBRICK ON CREATE SET s.id = toString(id(s)) RETURN s',
'RETURN sec AS s',
{sec: sec, line: line}) YIELD value
WITH value.s AS s,line,c,r
SET s.identifier=line.CODE_SBRICK
SET s.region=line.TERRITOIRE
SET s.regionIdentifier=line.CODE_TER
SET s.city=line.BRICK
SET s.cityIdentifier=line.CODE_BRICK
SET s.description=line.SOUSBRICK
SET s.zip=line.SOUSBRICK
SET s.sectorName = line.SOUSBRICK
WITH s,c,r,line
MATCH (s {identifier:line.CODE_SBRICK}),(r{identifier:line.CODE_TER})
MERGE (s)-[:IS_A_SECTOR_BELONGING_TO_THAT_REGION]->(r)
WITH s,c,r,line
MATCH (s {identifier:line.CODE_SBRICK}),(c{identifier:line.CODE_BRICK})
MERGE (s)-[:IS_A_SECTOR_BELONGING_TO_THAT_CITY]->(c)
Результат:
Установка 28271 свойств, создание 3400 отношений, выполнено через 34985 мс.
Потребовалось около 35 секунд, чтобы загрузить csv в neo4j db.пожалуйста, правильно ли это идеально с точки зрения производительности?
для файла CSV, содержащего 1665 строк CSV, каждая строка содержит 6 полей: два первых поля для (Регион), третье и четвертое (Город) и пятое и шестое для (Сектор).