cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Cannot access map item from apoc.load.csv

this being the content of my "taxonomy.CSV" file:

Level1,Level2,Tree Path,Id,Code,Description,Long Description,Context,Type,Active,Code Valid from,Node Valid from,Node Valid to
1,1,(Root Code),31102727,Zone,Zone,,TEST,Taxonomy,A,31/01/2020,,
2,2,31085110,31085110,CAI,Asia,,TEST,Zone,A,4/8/2017,,

by running
CALL apoc.load.csv('taxonomy.csv') yield map return map,map['Id'],map['Tree Path'],map['Level1'],map['Level2'] limit 5

I cannot access the values on the first column - they are always null.
I've tried renaming the column -> same (=null).
I've duplicated the column, initially called "Level" and new it's Level1 and Level2 and Level2 can be access, but Level1 is always null

Result (removed some content from map to make used fields more visible):

map
{
  "Tree Path": "(Root Code)",
  "Level2": "1",
  "Level1": "1",
  "Id": "31102727"
}
map['Id']	map['Tree Path']	map['Level1']	map['Level2']

"31102727"	"(Root Code)"	null	"1"

Is there some parameter i am missing, some little frustration disabler flag i need to use?

8 REPLIES 8

mdfrenchman
Graph Voyager

@gabriel.toma have you tried map.Id, map.Level1, map.Level2 ?
LOAD CSV WITH HEADERS makes the fields accessible in this way. I'm ASSUMING that apoc.load.csv uses the same logic underneath.

well, the reason I use the apoc variant is that LOAD CSV only outputs just "line", whereas for apoc.load.csv also outputs the map of the line, which I can use to setup the node immediately, using set p = map (p being the new node).
With LOAD CSV I would need to individually access each and every attribute, which is a no-go for my purpose.

If you use WITH HEADERS it gives you a map as well.... or it does for me (v 3.5.17 enterprise)

pretty standard pattern for us is to import a row, parse the fields that need formatting, then load the rest into the Node.

LOAD CSV WITH HEADERS FROM
'https://somewhere.com/sample.csv' AS line
CREATE (n)
SET n += line

Thanks, Mike, will try this.

wirselix
Node Clone

Hi Gabriel,

Hi have experienced the same problem accessing the first column when using apoc.load.csv.
Using the classical LOAD CSV including the statemen 'WITH HEADERS' is definitely an option. But not in my case. Apoc.load.csv also return with an index per line, which is crucial in my case. Classicla LOAD CSV does not provide this index per line. So I am still stuck, due this potential buck within apoc.load.csv
My workaround: I am adding an empty column at left of my csv file BEFORE running apoc.load.csv
Best
Markus

Thank you, Markus
In the end, I did the same (adding a column before the first column)
Opened https://github.com/neo4j/neo4j/issues/12587

Can you folks please check if you have a byte order mark character at the beginning of your file? That could potentially pollute the header string.
Maybe use hexdump or similar tools to inspect.
To get rid of BOM run

sed '1s/^\xEF\xBB\xBF//' < orig.txt > new.txt

Hello Stefan,
As I don't have sed installed, could you please be so kind to check attached file?
taxonomy_min.zip.txt (314 Bytes)
You may have to remove ".txt" from file name before unarchiving.