Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4j Import tool backslash escaped

Tags:

java

neo4j

I have to import a huge dataset and i use the neo4j-import tool. However my dataset follows the structure below :

1,"lorem1", "ipsum1","foo1"
2,"lorem2", "ipsum2","foo2"
3,"lorem3", "ipsum3","\"

And it throws an error when it reads "\".I know it's the backslash character which means it is waiting a quotation. I would like to know if it's possible to deactivate the backslash meaning in the neo4j-import tool ?

like image 274
H3lium Avatar asked Mar 16 '23 08:03

H3lium


1 Answers

I think that this is an issue with the tool that you used to export the CSV having a different idea what the CSV standard is than Neo4j. This is understandable because the CSV format isn't well standardized ;)

According to neo4j-import --help:

--quote <quotation-character>
  Character to treat as quotation character for values in CSV data. The default
  option is ". Quotes inside quotes escaped like """Go away"", he said." and "\"Go
  away\", he said." are supported. If you have set "'" to be used as the quotation
  character, you could write the previous example like this instead: '"Go away",
  he said.'

So this means that Neo4j allows you to escape quotes both with double quoting ("") and with backslash escaping (\"). Normally what I've seen is one or the other, and of course both sides need to agree on what the format is.

I would guess if you escaped your backslashes like this that it might work:

1,"lorem1", "ipsum1","foo1"
2,"lorem2", "ipsum2","foo2"
3,"lorem3", "ipsum3","\\"

You could also use that command to change your quote character (say to ' or even |). Of course you would need to re-generate your CSV with that in mind.

But no, it doesn't look like there's a way to have Neo4j change the way that it interprets escaped quotes in CSV.

like image 65
Brian Underwood Avatar answered Mar 27 '23 14:03

Brian Underwood