Vicente
Vicente

Reputation: 35

Neo4j Cypher - adding a property with LOAD CSV

I have a set of nodes created using file_A which contains a column with the 'id' of each node. It has been created using this Cypher query (in Java):

USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM 'file:file_A' AS line FIELDTERMINATOR '\t'
CREATE (c:Node {nodeId:line.id})

Now I have another file (file_B) which contains four columns: id, description, prop2 and prop3. I need to assign a description (property 'nodeDesc') to each of the nodes created before. These descriptions will be read from the 'description' column of file_B. Moreover, to assign this value to the 'nodoDesc' property of the node, both 'prop2' and 'prop3' must be equal to '1'. For this purpose I use this Cypher query:

USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM 'file:file_B' AS line FIELDTERMINATOR '\t'
MATCH (c:Node)
WHERE c.nodeId=line.id AND line.prop2='1' AND line.prop3='1'
SET c.nodeDesc = line.description

file_B contains some descriptions for each node, but only one of them has both 'prop2' and 'prop3' equal to '1'. And that is the one I want to assign to the property of the node.

The problem I obtain after executing the previous query is that some of the nodes don't have description. After performing several tests, I have verified that it doesn't do the MATCH of the 'nodeId' with the column 'id' of file_B, but in that column it is the 'nodeId', and both 'prop2' and 'prop3' are equal to 1'.

Note: file_A has 400.000 rows aprox., and file_B has 1.300.000 rows aprox.

Thanks.

Upvotes: 1

Views: 841

Answers (1)

InverseFalcon
InverseFalcon

Reputation: 30417

You may want to make sure you aren't comparing integers to strings. That can often be the source of mismatches like these.

And if both values are strings, then you may want to check to see if one string or the other has trailing (or preceding) spaces.

Upvotes: 0

Related Questions