neo4j load csv invalid "ON MATCH"

Lior Goldemberg

I'm loading a file using the LOAD CSV command,and i have a strange situation, when a new row gets a propery added in the "on match" block.

here is the code:

USING PERIODIC COMMIT 10000 LOAD CSV WITH HEADERS FROM 'file://1.csv'     
AS line 
FIELDTERMINATOR '|'

WITH line, split(line.list_ites, ',') AS items UNWIND items AS _items 

MERGE (session :Session { wz_session:line.session }) 
ON CREATE SET session.created = timestamp(),session.batch_id='60893068766' 
ON MATCH SET session.updated = timestamp() 

MERGE (hit :Hit { id:line.hit_id,date_time:TOINT(line.date_time) }) 
ON CREATE SET hit.created = timestamp() 
ON MATCH SET hit.updated = timestamp()

 FOREACH(q IN (CASE WHEN trim(line.list_ites) <> '&' THEN _items ELSE [] END) |   //cypher doesn't have IF
            MERGE (i:ListItems {key: q,name:split(q,'=')[0],value: split(q,'=')[1]}) 
            CREATE (hit)-[:WITH_QUERY]->(i)
         )

now this line should never happen

ON MATCH SET hit.updated = timestamp()

as the hit_id is unique, and yet- i see nodes from type Hit with updated=xxx (i've verified with the file that ids of these nodes appear once using grep [hit_id] 1.csv)

im pretty sure there is something wrong with this line:

split(line.list_ites, ',') AS items UNWIND items AS _items 

or with the loop

help with we appritiated,

Lior

UPDATE:

I removed this line:

 split(line.list_ites, ',') AS items UNWIND items AS _items 

and also the foreach loop, and indeed i dont see any "updated" field with value. still i must fix it, cause i can't really remove it from the final code

Michael Hunger

this is because it merges not only on hit_id but also on date_time as you specified both in the MERGE clause

you should change it to:

MERGE (hit :Hit { id:line.hit_id }) 
ON CREATE SET hit.created = timestamp(), hit.date_time=TOINT(line.date_time)
ON MATCH SET hit.updated = timestamp()

Update

It does not really make sense what you do with _items. Esp as you pass it to foreach as collection while it can't be a collection.

Perhaps use an inner foreach loop:

USING PERIODIC COMMIT 10000 LOAD CSV WITH HEADERS FROM 'file://1.csv'     
AS line FIELDTERMINATOR '|'

MERGE (session :Session { wz_session:line.session }) 
ON CREATE SET session.created = timestamp(),session.batch_id='60893068766' 
ON MATCH SET session.updated = timestamp() 

MERGE (hit :Hit { id:line.hit_id,date_time:TOINT(line.date_time) }) 
ON CREATE SET hit.created = timestamp() 
ON MATCH SET hit.updated = timestamp()

FOREACH (_items IN split(line.list_ites, ',') |
  FOREACH(q IN (CASE WHEN trim(line.list_ites) <> '&' THEN _items ELSE [] END) |               
    MERGE (i:ListItems {key: q, name:split(q,'=')[0], value: split(q,'=')[1]}) 
    CREATE (hit)-[:WITH_QUERY]->(i)
  )
)

But better would be to move the unwind to the end:

...
WHERE trim(line.list_ites) <> '&'
UNWIND split(line.list_ites, ',') AS _items
UNWIND _items as q
WITH q,split(q,'=') as parts, hit
MERGE (i:ListItems {key: q}) ON CREATE SET i.name=parts[0], i.value=parts[1]
CREATE (hit)-[:WITH_QUERY]->(i)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Neo4j load csv file

From Dev

Neo4J custom load CSV

From Dev

Neo4j load csv file

From Dev

Load CSV into neo4j does not fill in relationship properties

From Dev

Neo4j Load CSV Import Stalling

From Dev

Neo4j toInt conversion on LOAD CSV

From Dev

Cypher query, Load CSV not responding in Neo4j 2.1

From Dev

neo4j: Cypher LOAD CSV with uuid

From Dev

Neo4j Load csv on create set if not null

From Dev

Neo4J Load CSV -> URI is not hierarchical

From Dev

Load CSV into neo4j does not fill in relationship properties

From Dev

Neo4j relationship not getting added using Load csv

From Dev

neo4j: How to load CSV using conditional correctly?

From Dev

How to load a large csv file into Neo4j

From Dev

neo4j LOAD CSV returns Couldn't Load external resource - neo4j lost in directory

From Dev

Load CSV Fails in Cypher + Neo4j "LoadExternalResourceException: Couldn't load the external resource at:"

From Dev

neo4j: LOAD CSV doubled first data record of the CSV

From Dev

neo4j: LOAD CSV doubled first data record of the CSV

From Dev

Neo4j 3.x LOAD CSV absolute file path

From Dev

Neo4j Cypher - creating nodes and setting labels with LOAD CSV

From Dev

Neo4j Cypher: MERGE conditionally with values from LOAD CSV

From Dev

How to use WHERE and IN to update attributes in Neo4j comblined with LOAD CSV?

From Dev

Neo4j LOAD CSV fails when multiline fields are encountered

From Dev

can I use constraint and index in a single query to load csv to neo4j?

From Dev

Neo4j indexing - what should I index to speed up a CSV load?

From Dev

Why Neo4j CSV loader doesn't increment the load with large number of records

From Dev

How does neo4j on Windows resolve file name paths in cypher load csv in interactive browser session?

From Dev

Why would the same load csv in neo4j take exponential longer when run a second time (on a clean db)?

From Dev

Why would the same load csv in neo4j take exponential longer when run a second time (on a clean db)?

Related Related

  1. 1

    Neo4j load csv file

  2. 2

    Neo4J custom load CSV

  3. 3

    Neo4j load csv file

  4. 4

    Load CSV into neo4j does not fill in relationship properties

  5. 5

    Neo4j Load CSV Import Stalling

  6. 6

    Neo4j toInt conversion on LOAD CSV

  7. 7

    Cypher query, Load CSV not responding in Neo4j 2.1

  8. 8

    neo4j: Cypher LOAD CSV with uuid

  9. 9

    Neo4j Load csv on create set if not null

  10. 10

    Neo4J Load CSV -> URI is not hierarchical

  11. 11

    Load CSV into neo4j does not fill in relationship properties

  12. 12

    Neo4j relationship not getting added using Load csv

  13. 13

    neo4j: How to load CSV using conditional correctly?

  14. 14

    How to load a large csv file into Neo4j

  15. 15

    neo4j LOAD CSV returns Couldn't Load external resource - neo4j lost in directory

  16. 16

    Load CSV Fails in Cypher + Neo4j "LoadExternalResourceException: Couldn't load the external resource at:"

  17. 17

    neo4j: LOAD CSV doubled first data record of the CSV

  18. 18

    neo4j: LOAD CSV doubled first data record of the CSV

  19. 19

    Neo4j 3.x LOAD CSV absolute file path

  20. 20

    Neo4j Cypher - creating nodes and setting labels with LOAD CSV

  21. 21

    Neo4j Cypher: MERGE conditionally with values from LOAD CSV

  22. 22

    How to use WHERE and IN to update attributes in Neo4j comblined with LOAD CSV?

  23. 23

    Neo4j LOAD CSV fails when multiline fields are encountered

  24. 24

    can I use constraint and index in a single query to load csv to neo4j?

  25. 25

    Neo4j indexing - what should I index to speed up a CSV load?

  26. 26

    Why Neo4j CSV loader doesn't increment the load with large number of records

  27. 27

    How does neo4j on Windows resolve file name paths in cypher load csv in interactive browser session?

  28. 28

    Why would the same load csv in neo4j take exponential longer when run a second time (on a clean db)?

  29. 29

    Why would the same load csv in neo4j take exponential longer when run a second time (on a clean db)?

HotTag

Archive