Относительно этого предыдущего вопроса Как сделать запрос Cypher для обработки обоих случаев без дублирования узлов
Я пытался решить эту проблему с помощью apoc.do.when, но я получил эту ошибку
Я не знаю, как решить эту проблему.
Neo.DatabaseError.Statement.ExecutionFailed Планировщик RULE не поддерживает процедуры вызова
LOAD CSV WITH HEADERS FROM "file:///the-file-name.csv" as
line FIELDTERMINATOR ','
OPTIONAL MATCH (n:Region)
WHERE n.region contains "BLANKEMPTYVIDE" AND n.identifier= line.CODE_TER
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})
CREATE UNIQUE (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})
CREATE UNIQUE (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})
CREATE UNIQUE (s)-[:IS_A_SECTOR_BELONGING_TO_THAT_CITY]->(c)
the-file-name.csv находится на предыдущем вопросе Как сделать запрос Cypher для обработки обоих случаев без дублирования узлов
Обновить с помощьюсоветы cybersam ¸
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)
Когда я заменяю Create Unique на MERGE CLAUSE Выполнение Cypher завершается с ошибкой Neo.ClientError.Statement.SyntaxError: Переменная line
не определена (строка12, столбец 20 (смещение: 469)) «WITH value.r AS r, line» ^.
что я делаю, как показано ниже.1-й apoc.do.when счастливо использует строковую переменную, но когда шифр достигает (WITH value.r AS r, строка), я получаю взломанный код с ошибкой Neo.ClientError.Statement.SyntaxError: Строка переменной не определена
Окончательное обновление по совету киберсамов, и оно работает отлично и отлично.
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)