[Neo4J 2.1.2] / Cypher / Returning array property associated to an aggregate in one shot

37 views
Skip to first unread message

Michael Azerhad

unread,
Aug 7, 2014, 3:01:55 PM8/7/14
to ne...@googlegroups.com
Hi,

Let's suppose this Cypher query snippet: 

RETURN user.name, count(game.name)


=> a user can have multiple video games

No matter the example is, the important thing is that I can count names of user's video games associated with the user's name. 

Result would be:

            NAME                    NUMBER_OF_GAMES
           
Michael                       18


Now, suppose that the user.name is replaced by an array property: let's imagine user.ranks       

I expect the output to be:

           RANKS                  NUMBER_OF_GAMES
         
[1,2,3]                      18  


However the result is a cartesian product over the array:

          RANKS                  NUMBER_OF_GAMES
             
1                     ... //no matter the number of games is
             
2                     ...
             
3                     ...

          
Why isn't it possible to return the array in one shot ?

Thanks,

Michael 

Michael Azerhad

unread,
Aug 7, 2014, 4:15:53 PM8/7/14
to ne...@googlegroups.com
I managed to do the trick with: 

RETURN extract(d IN user.ranks | d) as ranks, count(game.name

=> one shot :)

Michael

Michael Hunger

unread,
Aug 7, 2014, 6:06:28 PM8/7/14
to ne...@googlegroups.com
Something is wrong there.

An array property is never converted into individual rows by cypher you must have done something differently.

Can you please share the full query?

Just tried it, works perfectly fine.




--
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 Azerhad

unread,
Aug 7, 2014, 7:18:19 PM8/7/14
to ne...@googlegroups.com
Hi Michael :)

So here's the initial full query (with the non-expected output, no "one shot").
The context is:  I want to retrieve the number of participants corresponding to meetings that the user 123 made (meaning participated too), associated to a meeting's array properties.

MATCH (meeting:Meeting)<-[:TO]-(part)-[:PARTICIPATES]->(user:User {id: "123"})   //traverse user123's participations
MATCH
(meeting)<-[:TO]-(participation)-[:PARTICIPATES]->(participant)  //traverse to retrieve all the participants for the meetings matched
RETURN meeting
.myArrayProperties AS myArrayProperties, count(participant) AS total_participants

Didn't display the whole array in one column. 
However, if I replace the array properties with a standard field like, meeting.title, it works.
So, arrays are weird.. IMHO ;)

Here's what I did to fix it:

MATCH (meeting:Meeting)<-[:TO]-(part)-[:PARTICIPATES]->(user:User {id: "123"})
MATCH
(meeting)<-[:TO]-(participation)-[:PARTICIPATES]->(participant)
RETURN extract
(property IN meeting.myArrayProperties | property) AS myArrayProperties, count(participant) AS total_participants

Thanks for your feedback, I appreciate.

Michael

Michael Azerhad

unread,
Aug 8, 2014, 11:38:07 AM8/8/14
to ne...@googlegroups.com
Hi Michael,

What better than a GraphGist to show you the issue :) 


So I would expect the output: 

MyMeetingTitle[1, 2, 3]2

rather than:

MyMeetingTitle[1, 2, 3]1
MyMeetingTitle[1, 2, 3]1

Do you see an obvious reason ?

Many thanks, 

Michael
 

Michael Azerhad

unread,
Aug 8, 2014, 12:05:21 PM8/8/14
to ne...@googlegroups.com
I've just updated the graphgist: http://gist.neo4j.org/?fc9672035185189521cf  in order to better explain my issue.
In case where someone already opened it..

Michael Hunger

unread,
Sep 1, 2014, 7:17:48 AM9/1/14
to ne...@googlegroups.com
Hi Michael,

thanks again for pointing it out. It was a Cypher Bug which is fixed in the next release.

A workaround is to convert the array into a collection as you already showed.

Cheers,

Michael


michael azerhad

unread,
Sep 1, 2014, 7:23:06 AM9/1/14
to ne...@googlegroups.com

Hi Michael,

Good to know :) 

Thanks a lot for warning me!

Michael 




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/THvROyg1W0Y/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