0
votes

I have edges like this:

(People)-[:USE]->(Product)
(People)-[:REVIEW]->(Product)

Now I have a new csv of People who are reviewers but they are missing some of the attributes I have already.

I want to do something like:

LOAD CSV WITH HEADERS FROM "file:///abcd.csv" AS row 
MERGE (svc:Consumer {name: row.referring_name})
ON CREATE SET
    svc.skewNum = toInteger(row.skew_num)
MERGE (p:PrimaryConsumer) WHERE p.name = svc.name
ON MATCH SET
    svc.city = p.city,
    svc.latitude = toFloat(p.latitude),
    svc.longitude = toFloat(p.longitude),
    svc.consumerId = toInteger(p.primaryConsumerId)

Which borks:

Neo.ClientError.Statement.SyntaxError: Invalid input 'H': expected 'i/I' (line 10, column 28 (offset: 346)) "MERGE (p:PrimaryConsumer) WHERE p.name = svc.name"

I am 100% assured that the names are unique and will match a unique consumer name in the existing set of nodes (to be seen).

How would I add existing attributes to new data when I have a match on unique node attributes? (I am hoping to get unique id's, but I have to be able to perform an update to the new data on match)

Thank you.

This is the entire cypher script -- modified as per @cypher's input.

 USING PERIODIC COMMIT
    LOAD CSV WITH HEADERS FROM "file:///abcde.csv" AS row
    MERGE (svc:Consumer {name: row.referring_name})
    ON CREATE SET
        svc.skeyNum = toInteger(row.skew_num)
        MATCH (p:primaryConsumer {name: svc:name})
    ON MATCH SET
        svc.city = p.city,
        svc.latitude = toFloat(p.latitude),
        svc.longitude = toFloat(p.longitude),
        svc.providerId = toInteger(p.providerId)
    MERGE (spec:Product {name: row.svc_prod_name})
    ON CREATE SET
        spec.name = row.svc_prov_name,
        spec.skew = toInteger(row.skew_id),
        spec.city = row.svc_prov_city,
        spec.totalAllowed = toFloat(row.total_allowed)
    MERGE (svc)-[r:CONFIRMED_PURCHASE]->(spec)
    ON MATCH SET r.totalAllowed = r.totalAllowed + spec.totalAllowed
    ON CREATE SET r.totalAllowed = spec.totalAllowed
;
1

1 Answers

2
votes

MERGE does not accept a WHERE clause.

Change this:

MERGE (p:PrimaryConsumer) WHERE p.name = svc.name

to this:

MERGE (p:PrimaryConsumer {name: svc.name})

[EDIT]

You entire query should then look like this:

LOAD CSV WITH HEADERS FROM "file:///abcd.csv" AS row 
MERGE (svc:Consumer {name: row.referring_name})
ON CREATE SET
    svc.skewNum = toInteger(row.skew_num)
MERGE (p:PrimaryConsumer {name: svc.name})
ON MATCH SET
    svc.city = p.city,
    svc.latitude = toFloat(p.latitude),
    svc.longitude = toFloat(p.longitude),
    svc.consumerId = toInteger(p.primaryConsumerId)