Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apoc.merge does not return statistics #3652

Closed
nielsjansendk opened this issue Jul 11, 2023 · 3 comments
Closed

apoc.merge does not return statistics #3652

nielsjansendk opened this issue Jul 11, 2023 · 3 comments

Comments

@nielsjansendk
Copy link

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)

  1. start neo4j desktop
  2. create a new database running neo4j 5.8.0
  3. install apoc
  4. start the database
  5. 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
@gem-neo4j
Copy link
Contributor

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!

@nielsjansendk
Copy link
Author

@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?

@gem-neo4j
Copy link
Contributor

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants