休息片刻之后,我最近一直在使用Neo4j导入工具 ,并遇到了我最初不理解的有趣的错误消息。
我有一些CSV文件,其中包含要导入Neo4j的节点。 它们的内容如下所示:
$ cat people_header.csv
name:ID(Person)
$ cat people.csv
"Mark"
"Michael"
"Ryan"
"Will"
"Jennifer"
"Karin"
$ cat companies_header.csv
name:ID(Company)
$ cat companies.csv
"Neo4j"
我发现使用单独的头文件更容易,因为我经常使用列名进行拼写错误,并且更新单个行文件比打开数百万行文件并更改第一行更容易。
我运行以下命令从这些文件创建新的Neo4j数据库:
$ ./bin/neo4j-admin import \
--database=blog.db \
--mode=csv \
--nodes:Person people_header.csv,people.csv \
--nodes:Company companies_heade.csv,companies.csv
导致此错误消息:
Neo4j version: 3.3.3
Importing the contents of these files into /Users/markneedham/Library/Application Support/Neo4j Desktop/Application/neo4jDatabases/database-b59e33d5-2060-4a5d-bdb8-0b9f6dc919fa/installation-3.3.3/data/databases/blog.db:
Nodes:
:Person
/Users/markneedham/Library/Application Support/Neo4j Desktop/Application/neo4jDatabases/database-b59e33d5-2060-4a5d-bdb8-0b9f6dc919fa/installation-3.3.3/people_header.csv
/Users/markneedham/Library/Application Support/Neo4j Desktop/Application/neo4jDatabases/database-b59e33d5-2060-4a5d-bdb8-0b9f6dc919fa/installation-3.3.3/people.csv
:Company
/Users/markneedham/Library/Application Support/Neo4j Desktop/Application/neo4jDatabases/database-b59e33d5-2060-4a5d-bdb8-0b9f6dc919fa/installation-3.3.3/companies.csv
...
Import error: Mixing specified and unspecified group belongings in a single import isn't supported
Caused by:Mixing specified and unspecified group belongings in a single import isn't supported
java.lang.IllegalStateException: Mixing specified and unspecified group belongings in a single import isn't supported
at org.neo4j.unsafe.impl.batchimport.input.Groups.getOrCreate(Groups.java:52)
at org.neo4j.unsafe.impl.batchimport.input.csv.InputNodeDeserialization.initialize(InputNodeDeserialization.java:60)
at org.neo4j.unsafe.impl.batchimport.input.csv.InputEntityDeserializer.initialize(InputEntityDeserializer.java:68)
at org.neo4j.unsafe.impl.batchimport.input.csv.ParallelInputEntityDeserializer.lambda$new$0(ParallelInputEntityDeserializer.java:104)
at org.neo4j.unsafe.impl.batchimport.staging.TicketedProcessing.lambda$submit$1(TicketedProcessing.java:103)
at org.neo4j.unsafe.impl.batchimport.executor.DynamicTaskExecutor$Processor.run(DynamicTaskExecutor.java:237)
输出实际上有助于指出要从中导入哪些文件,我们可以在“公司”部分下看到头文件丢失。
由于试图输入companies_header.csv当我做了错字的结果,该工具现在会将companies.csv的第一行作为标题,并因为我们还没有在该行指定的一组(如公司,个人)我们收到这个错误。
让我们修复打字错误,然后重试:
$ ./bin/neo4j-admin import \
--database=blog.db \
--mode=csv \
--nodes:Person people_header.csv,people.csv \
--nodes:Company companies_header.csv,companies.csv
Neo4j version: 3.3.3
Importing the contents of these files into /Users/markneedham/Library/Application Support/Neo4j Desktop/Application/neo4jDatabases/database-b59e33d5-2060-4a5d-bdb8-0b9f6dc919fa/installation-3.3.3/data/databases/blog.db:
Nodes:
:Person
/Users/markneedham/Library/Application Support/Neo4j Desktop/Application/neo4jDatabases/database-b59e33d5-2060-4a5d-bdb8-0b9f6dc919fa/installation-3.3.3/people_header.csv
/Users/markneedham/Library/Application Support/Neo4j Desktop/Application/neo4jDatabases/database-b59e33d5-2060-4a5d-bdb8-0b9f6dc919fa/installation-3.3.3/people.csv
:Company
/Users/markneedham/Library/Application Support/Neo4j Desktop/Application/neo4jDatabases/database-b59e33d5-2060-4a5d-bdb8-0b9f6dc919fa/installation-3.3.3/companies_header.csv
/Users/markneedham/Library/Application Support/Neo4j Desktop/Application/neo4jDatabases/database-b59e33d5-2060-4a5d-bdb8-0b9f6dc919fa/installation-3.3.3/companies.csv
...
IMPORT DONE in 1s 5ms.
Imported:
7 nodes
0 relationships
7 properties
Peak memory usage: 480.00 MB
成功!