Cypher Count with distinct and nulls

1,295 views
Skip to first unread message

kantube

unread,
Feb 7, 2012, 12:23:49 PM2/7/12
to ne...@googlegroups.com
Cypher 1.6

i want to count distinct nodes but ran in to an issue if the match clause includes optional relationships, for example:

start a = node(0)
match a-[:friend]->b-[?:like]->d
return count(distinct b), count(distinct d)

if there is a friend that has no "like" this throws an error "Flat hash tables cannot contain null elements"

this is just a sample query but demonstrates my issue.  i am trying to do some reporting and summing up of the data and need to count distinct elements.  if i remove the distinct my counts are incorrect (well correct if you want to count duplicates).

is there a way to do this with cypher?  if not can i do this with gremlin?

thanks

Marko Rodriguez

unread,
Feb 7, 2012, 12:41:33 PM2/7/12
to ne...@googlegroups.com
Hi,

Here is the respective Gremlin form:

g.V.out('knows').as('a').out('created').as('b').optional(1).table(t)

Here it is in action over the toy TinkerPop graph:

gremlin> g = TinkerGraphFactory.createTinkerGraph()
==>tinkergraph[vertices:6 edges:6]
gremlin> t = new Table()
gremlin> g.V.out('knows').as('a').out('created').as('b').optional(1).table(t).iterate()
==>null
gremlin> t 
==>[a:v[2], b:null]
==>[a:v[4], b:v[3]]
gremlin> t.getColumn(0)._().dedup.count()
==>2
gremlin> t.getColumn(1)._().dedup.count()
==>2

HTH,
Marko.

Andres Taylor

unread,
Feb 7, 2012, 1:38:54 PM2/7/12
to ne...@googlegroups.com
On Tue, Feb 7, 2012 at 6:23 PM, kantube <mic...@mkanner.com> wrote:
Cypher 1.6

i want to count distinct nodes but ran in to an issue if the match clause includes optional relationships, for example:

start a = node(0)
match a-[:friend]->b-[?:like]->d
return count(distinct b), count(distinct d)

That should definitely work. Sorry you had to run into a bug.


Andrés
 

kantube

unread,
Feb 7, 2012, 2:06:44 PM2/7/12
to ne...@googlegroups.com
will this fix be in a snapshot that i can get?  thx.


the error message that was thrown by this error was a lot better then the error message of not saving puppies like this one gives
    • start a = node(0)
    • match a-[:friend]->b
    • where b-[:like]->() and ().Name? = 'myName'
    • return a, b

    this was just some fat fingers on copy/paste not intending to harm puppies


    Reply all
    Reply to author
    Forward
    0 new messages