apoc.merge does not return statistics
nielsjansendk opened this issue · comments
Expected Behavior (Mandatory)
I am expecting this query:
call apoc.merge.node(["MyNode"],{my_id: 1},
{test: "created"},
{test: "updated"}) yield node return node
To return a summary that includes statistics. This should be fixed, according to this: #2239
Actual Behavior (Mandatory)
The query returns the following summary:
{ "query": { "text": "call apoc.merge.node([\"MyNode\"],{my_id: 1},{test: \"created\"},{test: \"updated\"}) yield node return node", "parameters": {} }, "queryType": "rw", "counters": { "_stats": { "nodesCreated": 0, "nodesDeleted": 0, "relationshipsCreated": 0, "relationshipsDeleted": 0, "propertiesSet": 0, "labelsAdded": 0, "labelsRemoved": 0, "indexesAdded": 0, "indexesRemoved": 0, "constraintsAdded": 0, "constraintsRemoved": 0 }, "_systemUpdates": 0 }, "updateStatistics": { "_stats": { "nodesCreated": 0, "nodesDeleted": 0, "relationshipsCreated": 0, "relationshipsDeleted": 0, "propertiesSet": 0, "labelsAdded": 0, "labelsRemoved": 0, "indexesAdded": 0, "indexesRemoved": 0, "constraintsAdded": 0, "constraintsRemoved": 0 }, "_systemUpdates": 0 }, "plan": false, "profile": false, "notifications": [], "server": { "address": "localhost:7687", "agent": "Neo4j/5.8.0", "protocolVersion": 5 }, "resultConsumedAfter": { "low": 88, "high": 0 }, "resultAvailableAfter": { "low": 1, "high": 0 }, "database": { "name": "neo4j" } }
The stats should either have nodesCreated: 1 or propertiesSet: 1, depending on if the node is created or merged.
How to Reproduce the Problem
Steps (Mandatory)
- start neo4j desktop
- create a new database running neo4j 5.8.0
- install apoc
- start the database
- run the query
Specifications (Mandatory)
Currently used versions
Versions
- OS: MacOs Ventura 13.4.1
- Neo4j: 5.8.0
- Neo4j-Apoc: apoc-plus 5.8.0
Hi! I think you've misunderstood what the fix here did :)
To return a summary that includes statistics. This should be fixed, according to this: #2239
Procedures cannot report to the db statistics, and that is not something that APOC can make a fix for. What that change did, was add new procedures e.g apoc.merge.nodeWithStats
which returns a stats column from the procedure itself that you can use to see these values :) So if you would like stats, try out those procedures instead :D
Hope this helps!
@gem-neo4j Thanks, but that will not work inside apoc.periodic.iterate, is that correct? There is no way to assign the output from the stats column so it shows up in the updateStatistics output for apoc.periodic.iterate, is there?
Ah I see, yeah there is no way to do that. What I recommend in that case is to use Cypher instead, all the APOC procedure is doing is building a Cypher Query and executing it, so you could run it yourself:
e.g for your example:
CALL apoc.merge.node(["MyNode"],{my_id: 1}, {test: "created"}, {test: "updated"})
YIELD node
RETURN node
Is the same as running:
MERGE (n:MyNode { my_id: 1 })
ON CREATE SET n += {test: "created"}
ON MATCH SET n += {test: "updated"}
RETURN n
And by running this, you will get the statistics back as expected. I’d also recommend using CALL {} IN TRANSACTIONS
from Cypher instead as well! https://neo4j.com/docs/cypher-manual/current/clauses/call-subquery/