Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
on 04-21-2021 05:59 PM
Hello there
Is it me or the behaviour of MERGE has changed in Neo4j 4.2.5
I think it's because I'm using the SET i = data operator which replace everything.
But in the context of ON CREATE WITH a MERGE clause it should keep the property defined in the merge?
The last MERGE clause in this query doesn't actually add the id property to the Impression node when creating it. Therefore, if I run the query again I have duplicates spawning for execution of the query.
CALL apoc.load.csv('gs://attribution_audit_client_015/csv/bds_pm_media_daily.csv?authenticationType=PRIVATE_KEY',{
ignore:['LI_OneClick_Leads','ad_platform_cookie_hits','Lead_Form_Opens','Account_ID','Platform','Data_source','Account_Name','ad_platform_click_conv','source','medium','Campaign_Name'],
mapping:
{Date:{name:'date'}, Impressions:{name:'quantity', type:'int'}, Cost_USD:{name:'cost', type:'float'}, Clicks:{name:'clicks', type:'int'},Campaign_ID:{name:'campaign_id', type:'int'},Keyword_ID:{name:'keyword_id', type:'int'}}}
) YIELD map
WITH map.date + '-' + toString(map.keyword_id) AS id, {quantity:map.quantity, clicks:map.clicks, cost:map.cost, date:map.date} AS data, {name:map.campaign, id:map.campaign_id} AS campaign, {name:map.keyword, id:map.keyword_id} AS keywordMERGE (i:Impression {id:id})
ON CREATE SET i = data
Fixed by using the += operator.
But still, does the = operator should behaves differently in the context of ON CREATE WITH MERGE?
The = operator, when used in any kind of SET operation to a node (SET node = map
), replaces all of its properties with the contents of the map, essentially removing all existing properties first.
As you found, += will add to the existing properties (replacing where there is a property in the map that also exists on the node), and any other properties not being overwritten will remain.
I felt idiot when I figure it out