1
votes

I'm trying to load a locally stored .csv file into Neo4j. I've also tried publishing it to Google sheets but this has not got me closer to what I need.

I've stored the csv in my import folder and the file path is:

"C:\Users\FJ1993.Neo4jDesktop\neo4jDatabases\database-325e28a1-76ac-4268-820e-844bda8d4812\installation-3.4.0\import\GTD sample_location_target_attacker.csv

On trying to load into Neo4j I've tried two methods based on tutorials I've seen and the Neo4j documentation:

1)

LOAD CSV WITH HEADERS FROM "file://C:/Users/FJ1993/.Neo4jDesktop\neo4jDatabases/database-325e28a1-76ac-4268-820e-844bda8d4812\installation-3.4.0/import/GTD" sample_location_target_attacker.csv WITH line

Error is

Neo.ClientError.Statement.SyntaxError: Invalid input 'i': expected '\', ''', '"', 'b', 'f', 'n', 'r', 't', UTF16 or UTF32 (line 1, column 127 (offset: 126)) "LOAD CSV WITH HEADERS FROM "file://C:/Users/FJ1993/.Neo4jDesktop\neo4jDatabases/database-325e28a1-76ac-4268-820e-844bda8d4812\installation-3.4.0/import/GTD" sample_location_target_attacker.csv WITH line"

2)

LOAD CSV WITH HEADERS FROM "file://C:/Users/FJ1993/.Neo4jDesktop\neo4jDatabases/database-325e28a1-76ac-4268-820e-844bda8d4812\installation-3.4.0/import/GTD sample_location_target_attacker.csv" AS csvDoc

Error is

Neo.ClientError.Statement.SyntaxError: Invalid input 'i': expected '\', ''', '"', 'b', 'f', 'n', 'r', 't', UTF16 or UTF32 (line 1, column 127 (offset: 126)) "LOAD CSV WITH HEADERS FROM "file://C:/Users/FJ1993/.Neo4jDesktop\neo4jDatabases/database-325e28a1-76ac-4268-820e-844bda8d4812\installation-3.4.0/import/GTD sample_location_target_attacker.csv" AS csvDoc"

3) I've also tried to upload from a Google sheet which I published.

The link for this is https://docs.google.com/spreadsheets/d/e/2PACX-1vSOpbMUwFnf7gMYm7JaB3gzWGV7or0qU7cLIsjwApq4sH63v88O1fd0RrmbxvBlVWMfVASh0sw9zJX_/pubhtml

My Cypher is:

LOAD CSV WITH HEADERS FROM "https://docs.google.com/spreadsheets/d/e/2PACX-1vSOpbMUwFnf7gMYm7JaB3gzWGV7or0qU7cLIsjwApq4sH63v88O1fd0RrmbxvBlVWMfVASh0sw9zJX_/pubhtml" AS line RETURN 10

To which error message is:

Neo.DatabaseError.General.UnknownError: At https://docs.google.com/spreadsheets/d/e/2PACX-1vSOpbMUwFnf7gMYm7JaB3gzWGV7or0qU7cLIsjwApq4sH63v88O1fd0RrmbxvBlVWMfVASh0sw9zJX_/pubhtml @ position 4388 - 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: 'docs-smheo":'

Does anyone know how I can get the csv file into Neo4j? I am not proficient enough to write to the command line and am totally reliant on the GUI.

Thanks

3

3 Answers

3
votes

Looks like you had a quotation mark in the wrong place after "import/GTD", a missing forward slash after file and you shouldn't specify the full path.

You also have a mixture of forward and backward slashes in your file path. Use forward slashes, but since you don't specify the full path, this is only useful if you have folders within your import folder.

I recommend you remove the space after GTD, just to be safe.

Try this and I hope it helps:

LOAD CSV WITH HEADERS FROM "file:///GTD sample_location_target_attacker.csv" WITH line

Original

LOAD CSV WITH HEADERS FROM "file://C:/Users/FJ1993/.Neo4jDesktop\neo4jDatabases/database-325e28a1-76ac-4268-820e-844bda8d4812\installation-3.4.0/import/GTD" sample_location_target_attacker.csv WITH line
1
votes

First guess is you should precise the field separator with FIELDTERMINATOR ';' for ; which shouldn't be in your content. I use | whenever possible.

There is lots of free educational content on neo4j website, and nice books on the market add a pedagogical approach.

Shameless plug: I recommend "Learning Neo4j" Second edition (spoiler: i am the author)

1
votes

I think your problem is in the path to the import file.

When the error is thrown is there a '^' under the 'i' of '...4812\installation...'?

(It's hard to see, but I bet it's there!)

Cypher is parsing the command line, including the quoted file name, and interprets the '\' as the start of an escape sequence. It hasn't got as far as trying to read your input file.

You need to use '/' for your path delimiters.

Since the file you are loading is in the import directory you probably don't need the full path. I found:

LOAD CSV WITH HEADERS FROM "file:///Neo4jQuestion.csv" as line 
CREATE (SomeNode {location:line.location, target:line.target, attacker:line.attacker});

works on my Windows box. (Note the three slashes after 'file:')