neo4j-admin导入可以在出现导入错误的情况下跳过CSV行吗?

时间:2019-10-11 21:03:27

标签: csv import neo4j

我正在尝试使用neo4j-admin import用CSV输入数据填充neo4j数据库。根据文档,不支持使用\"引起的引号引起来,但是我的输入存在这些异常和其他格式异常。因此,neo4j-admin import显然无法输入CSV

> neo4j-admin import --mode=csv --id-type=INTEGER \
>    --high-io=true \
>    --ignore-missing-nodes=true \
>    --ignore-duplicate-nodes=true \
>    --nodes:user="import/headers_users.csv,import/users.csv"
Neo4j version: 3.5.11
Importing the contents of these files into /data/databases/graph.db:
Nodes:
  :user
  /var/lib/neo4j/import/headers_users.csv
  /var/lib/neo4j/import/users.csv

Available resources:
  Total machine memory: 15.58 GB
  Free machine memory: 598.36 MB
  Max heap memory : 17.78 GB
  Processors: 8
  Configured max memory: -2120992358.00 B
  High-IO: true


IMPORT FAILED in 97ms. 
Data statistics is not available.
Peak memory usage: 0.00 B
Error in input data
Caused by:ERROR in input
  data source: BufferedCharSeeker[source:/var/lib/neo4j/import/users.csv, position:91935, line:866]
  in field: company:string:3
  for header: [user_id:ID(user), login:string, company:string, created_at:string, type:string, fake:string, deleted:string, long:string, lat:string, country_code:string, state:string, city:string, location:string]
  raw field value: yyeshua
  original error: At /var/lib/neo4j/import/users.csv @ position 91935 -  there's a field starting with a quote and whereas it ends that quote there seems to be characters in that field after that ending quote. That isn't supported. This is what I read: 'Universidad Pedagógica Nacional \"F'

我的问题是,是否可以跳过或忽略neo4j-admin import引发错误的CSV文件格式错误的行。 the docs中似乎没有这样的选项。我了解使用LOAD CSV存在解决方案,并且CSV应该在导入之前进行预处理。注意解决格式问题后,我能够成功导入CSV。

1 个答案:

答案 0 :(得分:1)

也许值得描述批量导入程序和LOAD CSV之间的区别。

LOAD CSV将事务性数据加载到数据库中-这意味着您获得了所有的ACID优势,等等。其副作用是,这不是最快的数据加载方式。

批量导入程序假定数据为数据库就绪格式,您已经处理了重复项,将其转换为正确格式所需的任何处理等,并且只会按原样提取数据并按照指定的方式将其形成数据库。这不是事务性的数据加载,并且由于它假定正在加载的数据已经“准备好数据库”,因此确实非常迅速地将其提取。

还有其他导入数据的选项,但是通常,如果您需要在导入时进行某种行跳过/更正,您实际上并不想通过脱机批量导入器进行操作。我建议您在使用neo4j-admin import之前在CSV上进行某种形式的预处理,或者查看其他可用的导入选项之一,在其中可以指示如何处理格式较差的行。