[Idea] Declaring an expected result for write-based Cypher queries

17 views
Skip to first unread message

Byron Ruth

unread,
Nov 12, 2014, 5:27:06 PM11/12/14
to ne...@googlegroups.com
I am submitting Cypher queries over the HTTP transactional endpoint in batches and began using a pattern of adding an expected value as part of my query. For example, a query like this:

MATCH (s {foo: 1}),
     
(e {bar: 1})
CREATE
(s)-[:LINKS]->(e)
RETURN
1

would be submitted as:

{
   
"statement": <query>,
   
"parameters": null,
   
"expected": 1
}

the Neo4j client I wrote inspects the result and determines in it matches the expected result. The reason this is necessary is because if either MATCH fails, the CREATE will not occur and nothing will be returned. Since an error is not raised, I use the RETURN 1 as a sentinel for determining whether the query completely executed.

I was curious if the Neo4j team had any plans for providing a return value for Cypher query execution. Or consider an approach like this in which an agent can declare an expected value.

Michael Hunger

unread,
Nov 12, 2014, 8:50:32 PM11/12/14
to ne...@googlegroups.com
You can return count(*)

which would be 0 for the case that it didn't match
and 1 for the cases it matched.

you could even do

with count(*) as c
return c = 1 as successful

Afaik there are no plans for providing expected results (esp, as those can grow gigantic).

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Hunger

unread,
Nov 12, 2014, 8:50:50 PM11/12/14
to ne...@googlegroups.com
Just make sure to use labels with your property matches :)

Byron Ruth

unread,
Nov 13, 2014, 6:56:08 AM11/13/14
to ne...@googlegroups.com
Thanks Michael. The RETURN 1 approach has been working correctly for me and prevents needing to do a COUNT(*).
 
Afaik there are no plans for providing expected results (esp, as those can grow gigantic).

Yes of course :) As mentioned, I am only using this approach for write operations where no results are being returned.

Michael Hunger

unread,
Nov 13, 2014, 7:34:23 AM11/13/14
to ne...@googlegroups.com
Then you could also compare the results of the tx-endpoints in terms of nodes-created, properties-set, labels created etc.

if you provide the parameter as part of the statement { ..... "includeStats":true ... }

You get the statistics back.

HTH Michael


--

Byron Ruth

unread,
Nov 13, 2014, 7:38:57 AM11/13/14
to ne...@googlegroups.com, ne...@googlegroups.com
Ah! I didn't realize includeStats was an option. That would come in handy. Thank you. 




You received this message because you are subscribed to a topic in the Google Groups "Neo4j" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/neo4j/gwnFQCjkI7U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to neo4j+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages