Cypher: Nullpointer with 2 NOTs in the where clause

66 views
Skip to first unread message

Luanne Coutinho

unread,
May 1, 2012, 12:51:22 AM5/1/12
to ne...@googlegroups.com
Hi,

Is something wrong with this query or is it an issue with Cypher (1.7)-
The following query produces an NPE whether or not each NOT is grouped by parentheses- a single NOT works fine:

start n=node(1)
match (person)<-[:knows|works_with]-(n)-[?:friend]-(friend)-[?:knows|works_with]-(friendProfile)
where (not((person)-[:blocks]-(n))) and (not((friendProfile)-[:blocks]-(n)))
return person.name,friendProfile.name

java.lang.NullPointerException
at org.neo4j.cypher.internal.commands.HasRelationshipTo.isMatch(Predicate.scala:113)
at org.neo4j.cypher.internal.commands.Not.isMatch(Predicate.scala:94)
at org.neo4j.cypher.internal.commands.And.isMatch(Predicate.scala:72)
at org.neo4j.cypher.internal.pipes.FilterPipe$$anonfun$1.apply(FilterPipe.scala:31)
at org.neo4j.cypher.internal.pipes.FilterPipe$$anonfun$1.apply(FilterPipe.scala:31)
at scala.collection.TraversableLike$$anonfun$filter$1.apply(TraversableLike.scala:213)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:45)
at scala.collection.TraversableLike$class.filter(TraversableLike.scala:212)
at scala.collection.immutable.List.filter(List.scala:45)
at org.neo4j.cypher.internal.pipes.FilterPipe.createResults(FilterPipe.scala:31)
at org.neo4j.cypher.internal.pipes.ExtractPipe.createResults(ExtractPipe.scala:38)
at org.neo4j.cypher.internal.pipes.ColumnFilterPipe.createResults(ColumnFilterPipe.scala:37)
at org.neo4j.cypher.internal.executionplan.ExecutionPlanImpl$$anonfun$3$$anonfun$apply$1.apply(ExecutionPlanImpl.scala:62)
at org.neo4j.cypher.internal.executionplan.ExecutionPlanImpl$$anonfun$3$$anonfun$apply$1.apply(ExecutionPlanImpl.scala:62)
at org.neo4j.cypher.PipeExecutionResult.immutableResult(PipeExecutionResult.scala:36)
at org.neo4j.cypher.PipeExecutionResult.iterator(PipeExecutionResult.scala:138)
at org.neo4j.cypher.PipeExecutionResult.hasNext(PipeExecutionResult.scala:140)
at scala.collection.Iterator$$anon$19.hasNext(Iterator.scala:334)
at scala.collection.JavaConversions$IteratorWrapper.hasNext(JavaConversions.scala:562)

Thanks
Luanne

Luanne Coutinho

unread,
May 1, 2012, 1:37:05 AM5/1/12
to ne...@googlegroups.com
Ignore this for a bit...

Luanne Coutinho

unread,
May 1, 2012, 1:40:22 AM5/1/12
to ne...@googlegroups.com
Might have been the missing space between not and the starting parenthesis...

Luanne Coutinho

unread,
May 1, 2012, 1:52:14 AM5/1/12
to ne...@googlegroups.com
Okay sorry for all the mails, I'm a bit confused. My earlier queries worked fine without the space (with a single not). Trying to figure out the conditions under which this fails.

Luanne Misquiita

unread,
May 1, 2012, 4:44:38 AM5/1/12
to ne...@googlegroups.com
So I definitely get this exception with the query. The space between the not and the parenthesis does not matter. Any ideas why?

Sent from my iPad

Michael Hunger

unread,
May 1, 2012, 5:50:50 AM5/1/12
to ne...@googlegroups.com
Most probably due to the optional relationships, you might get null nodes in between.

coalesce doesn't work for nodes (except if you pass in something like the ref-node).

Could you try the ! modifier, which would probably cause the expression to evaluate to false if the node is null.

Cheers

Michael

Would you be able to set up a mini-graph in the neo4j-console, that exhibits the problem? http://console.neo4j.org?init=(0) gives you an empty one to start with or use console.neo4j.org with the matrix graph.
You can use mutating cypher or geoff to build up your graph.

Luanne Coutinho

unread,
May 1, 2012, 10:12:16 AM5/1/12
to ne...@googlegroups.com
Hi Michael,

Must be the optional path, but couldn't use the ! since it appears to work only on properties?
In any case, I created a sample of the graph at http://tinyurl.com/6lgcqab

Here is the part of the query that works:
start n=node(1)
match (person)<-[:knows|works_with]-(n)-[?:friend]-(friend)-[?:knows|works_with]-(friendProfile)
where (not((person)-[:blocks]-(n)))
return person.name,friendProfile.name

Adding the second not fails:
start n=node(1)
match (person)<-[:knows|works_with]-(n)-[?:friend]-(friend)-[?:knows|works_with]-(friendProfile)
where (not((person)-[:blocks]-(n))) and (not((friendProfile)-[:blocks]-(n)))
return person.name,friendProfile.name

I now realize with this and the previous question about transposing rows that what I'm trying to do is a union. In any case, please let me know if there's a better way to write this query or get it working, and whether I should just split into two separate queries.

Thanks
Luanne

Andres Taylor

unread,
May 2, 2012, 5:32:52 AM5/2/12
to ne...@googlegroups.com
On Tue, May 1, 2012 at 4:12 PM, Luanne Coutinho <luanne....@gmail.com> wrote:
Hi Michael,

Must be the optional path, but couldn't use the ! since it appears to work only on properties?
In any case, I created a sample of the graph at http://tinyurl.com/6lgcqab

Here is the part of the query that works:
start n=node(1)
match (person)<-[:knows|works_with]-(n)-[?:friend]-(friend)-[?:knows|works_with]-(friendProfile)
where (not((person)-[:blocks]-(n)))
return person.name,friendProfile.name

Adding the second not fails:
start n=node(1)
match (person)<-[:knows|works_with]-(n)-[?:friend]-(friend)-[?:knows|works_with]-(friendProfile)
where (not((person)-[:blocks]-(n))) and (not((friendProfile)-[:blocks]-(n)))
return person.name,friendProfile.name

I now realize with this and the previous question about transposing rows that what I'm trying to do is a union. In any case, please let me know if there's a better way to write this query or get it working, and whether I should just split into two separate queries.


Nice work Luanne. I couldn't re-produce the problem with the query someone else supplied, but with your graph set up and your query, it was super easy to locate and fix. Lovely!


Andrés

Luanne Coutinho

unread,
May 2, 2012, 5:37:30 AM5/2/12
to ne...@googlegroups.com
Andres, that's great, thanks. Till the fix is available, I've split into two queries.

Regards
Luanne

Andres Taylor

unread,
May 2, 2012, 5:41:03 AM5/2/12
to ne...@googlegroups.com
On Wed, May 2, 2012 at 11:37 AM, Luanne Coutinho <luanne....@gmail.com> wrote:
Andres, that's great, thanks. Till the fix is available, I've split into two queries.

It had nothing to do with the number of comparisons - just make sure to check for null before you check the relationships. Or, wait for the PR to be merged in :)

Andrés 

Luanne Coutinho

unread,
May 2, 2012, 5:56:02 AM5/2/12
to ne...@googlegroups.com
In this particular query, is it possible to check for a null before checking the relationship?
By splitting the query into two, I got rid of the optional part so that query will either return data or not.

-Luanne

Michael Hunger

unread,
May 2, 2012, 6:21:37 AM5/2/12
to ne...@googlegroups.com
not (node is null) AND node-[:rel]->other

??

Michael

Andres Taylor

unread,
May 2, 2012, 6:32:50 AM5/2/12
to ne...@googlegroups.com
On Wed, May 2, 2012 at 12:21 PM, Michael Hunger <michael...@neotechnology.com> wrote:
not (node is null) AND node-[:rel]->other

That's it, yes.

Andrés 

Luanne Coutinho

unread,
May 2, 2012, 8:26:03 AM5/2/12
to ne...@googlegroups.com
Perfect, thanks!
Reply all
Reply to author
Forward
0 new messages