Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Mixing Specified and Unspecified Group Belongings in a Single Import Isn't Supported

DZone's Guide to

Mixing Specified and Unspecified Group Belongings in a Single Import Isn't Supported

Have you come across this error while using the Neo4j Import Tool? This solution might be for you, then.

· Database Zone ·
Free Resource

Compliant Database DevOps and the role of DevSecOps DevOps is becoming the new normal in application development, and DevSecOps is now entering the picture. By balancing the desire to release code faster with the need for the same code to be secure, it addresses increasing demands for data privacy. But what about the database? How can databases be included in both DevOps and DevSecOps? What additional measures should be considered to achieve truly compliant database DevOps? This whitepaper provides a valuable insight. Get the whitepaper

I've been working with the Neo4j Import Tool recently after a bit of a break and ran into an interesting error message that I initially didn't understand.

I had some CSV files containing nodes that I wanted to import into Neo4j. Their contents look like this:

$ 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"

I find it easier to use separate header files because I often make typos with my column names and it's easier to update a single line file than to open a multi-million line file and change the first line.

I ran the following command to create a new Neo4j database from these files:

$ ./bin/neo4j-admin import \
--database=blog.db \
--mode=csv \
--nodes:Person people_header.csv,people.csv \
--nodes:Company companies_heade.csv,companies.csv

Which resulted in this error message:

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)

The output actually helpfully indicates which files it's importing from and we can see under the :Company section that the header file is missing.

As a result of the typo Ithat  made when trying to type companies_header.csv, the tool now treats the first line of companies.csv as the header and since we haven't specified a group (i.e. Company, Person) on that line we receive this error.

Let's fix the typo and try again:

$ ./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

Success!

Compliant Database DevOps and the role of DevSecOps DevOps is becoming the new normal in application development, and DevSecOps is now entering the picture. By balancing the desire to release code faster with the need for the same code to be secure, it addresses increasing demands for data privacy. But what about the database? How can databases be included in both DevOps and DevSecOps? What additional measures should be considered to achieve truly compliant database DevOps? This whitepaper provides a valuable insight. Get the whitepaper

Topics:
neo4j ,graph database ,database ,import ,tool ,nosql ,exception

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}