带有空单元格的Neo4j CSV文件加载 [英] Neo4j CSV file load with empty cells

查看:81
本文介绍了带有空单元格的Neo4j CSV文件加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一个基本的CSV文件加载到Neo4j数据库中,该数据库有两列-名称"和属性".名称列始终具有一个值,属性"列可以具有一个值或空格.我希望将值与关系"property1"关联起来.

I am loading a basic CSV file into Neo4j database which has got two columns - "name" and "property". The name column always has a value and "property" column can either have a value or a blank space. I would like to values to be linked with a relationship "property1".

我正在使用以下代码:

LOAD CSV WITH HEADERS FROM 'file:///fileName.csv' AS line
MERGE (Test_Document:A {name: line.name})
WITH line, Test_Document 
FOREACH (x IN CASE WHEN line.property IS NULL THEN [] ELSE [1] END |
  MERGE (Properties:B {property1: line.property})
WITH Test_Document, Properties
FOREACH (y IN CASE WHEN Properties IS NULL THEN [] ELSE [1] END |
  MERGE (Test_Document)-[:property1]->(Properties))

我收到一条错误消息:

Unexpected end of input: expected whitespace, LOAD CSV, START, MATCH, UNWIND, MERGE, CREATE, SET, DELETE, REMOVE, FOREACH, WITH, CALL, RETURN or ')' (line 8, column 54 (offset: 423))
"  MERGE (Test_Document)-[:property1]->(Properties))"

任何帮助将不胜感激.

推荐答案

查询存在两个问题:

  1. 第5行缺少结束括号
  2. Properties不在第二个FOREACH的范围内,因为它是在前一个FOREACH中声明的(在FOREACH中声明的别名仅在该FOREACH子句中限定)
  1. Missing a closing paren on line 5
  2. Properties is not in scope for the second FOREACH since it is declared in the previous FOREACH (aliases declared within a FOREACH are only scoped to within that FOREACH clause)

尝试一下:

LOAD CSV WITH HEADERS FROM 'file:///fileName.csv' AS line
MERGE (Test_Document:A {name: line.name})
WITH line, Test_Document 
FOREACH (x IN CASE WHEN line.property IS NULL THEN [] ELSE [1] END |
  MERGE (Properties:B {property1: line.property})
  MERGE (Test_Document)-[:property1]->(Properties)
)

这篇关于带有空单元格的Neo4j CSV文件加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆