Subtracting Cypher Queries

870 views
Skip to first unread message

Chris Bolton

unread,
Aug 17, 2012, 2:34:23 PM8/17/12
to ne...@googlegroups.com
Okay here is my latest concoction:

START n=node(127) MATCH(n)-[:friends]->(x) WITH n, collect(distinct x) as friends MATCH(n)-[:outer_only_friends]->(y) WITH n, collect(distinct y) as outer, friends RETURN collect(friends + outer) as stuff

and it works!

Is there any available syntax to subtract outer from friends? Effectively using a minus sign in place of the plus sign? I tried that. It throws a "Don't know how to subtract" error right now.

Any help would be appreciated.

Thanks.

Chris 

Michael Hunger

unread,
Aug 18, 2012, 3:31:19 AM8/18/12
to ne...@googlegroups.com
You would filter out the ones of the first that are part of the second with FILTER(x IN first : x IN second)

--
 
 

Peter Neubauer

unread,
Aug 18, 2012, 6:24:13 AM8/18/12
to ne...@googlegroups.com
That one is nifty! Chris, if you can make a small domain example with this filter and describe it, I would love to add it to http://docs.neo4j.org/chunked/snapshot/data-modeling-examples.html . Maybe you cangive me a console.neo4j.org example with some text?

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

Wanna learn something new? Come to @graphconnect.


--
 
 

Chris Bolton

unread,
Aug 18, 2012, 4:59:52 PM8/18/12
to ne...@googlegroups.com
Sounds good. I'll put something together and send it over.

Chris

--- On Sat, 8/18/12, Peter Neubauer <peter.n...@neotechnology.com> wrote:
--
 
 

Chris Bolton

unread,
Aug 20, 2012, 11:03:45 AM8/20/12
to ne...@googlegroups.com
Okay, I've run into a couple problems

1) When I run this
       RETURN collect (inner + outeronly + friends + outer) as total, filter(x in blocked + pending : x in total)") 

I get this ... NativeException: org.neo4j.cypher.SyntaxException: blocked + pending expected to be of type IterableType<AnyType> but it is of type ScalarType
from org/neo4j/cypher/internal/commands/Expression.scala:37:in `dependencies'

I meant to mention that earlier. My query with the collections returns an interesting Java/Scala thing that took some Ruby magic to get to. 

2) I attempted to recreate the Cypher query and sample data set for Peter in console but it didn't like me returning collections. http://console.neo4j.org/?id=ngb7xt

As always any help would be greatly appreciated.

Chris

--- On Sat, 8/18/12, Peter Neubauer <peter.n...@neotechnology.com> wrote:

From: Peter Neubauer <peter.n...@neotechnology.com>
Subject: Re: [Neo4j] Subtracting Cypher Queries
To: ne...@googlegroups.com
Date: Saturday, August 18, 2012, 3:24 AM

--
 
 

Andres Taylor

unread,
Aug 24, 2012, 9:24:25 AM8/24/12
to ne...@googlegroups.com
Hi Chris,

On Mon, Aug 20, 2012 at 5:03 PM, Chris Bolton <iknewt...@yahoo.com> wrote:
Okay, I've run into a couple problems

1) When I run this
       RETURN collect (inner + outeronly + friends + outer) as total, filter(x in blocked + pending : x in total)") 

I get this ... NativeException: org.neo4j.cypher.SyntaxException: blocked + pending expected to be of type IterableType<AnyType> but it is of type ScalarType
from org/neo4j/cypher/internal/commands/Expression.scala:37:in `dependencies'

This problem has been fixed in snapshot. Does that work for you?

Andrés

 

Andres Taylor

unread,
Aug 24, 2012, 9:56:36 AM8/24/12
to ne...@googlegroups.com
Hi Chris,

Me and Peter worked over your examples, and this is what I suggest you use:

start n=node(1)  
match (n)-[:FRIENDS]->(x) with collect(distinct x) as friends, n
match (n)-[:FAMILY]->(y)  with collect(distinct y)+friends as total, n, friends
match (n)-[:BLOCKED]->(z) with collect(distinct z) as blocked, total  
return total, filter(x in total : not x in blocked) as newtotal


HTH,

Andrés
Reply all
Reply to author
Forward
0 new messages