1

Using Cypher (Neo4j 2.1.2), it seems that array properties do not work well with aggregate functions.

For instance, I can have a RETURN clause like this:

RETURN meeting.title, count(participant) as number_part

Output: MyTitle 2

It well returns all the meetings's titles grouped by participants.

However, with an array as property rather than simple one like title, the output is strange:

 RETURN meeting.arrayProperty, count(participant) as number_part

Output:

MyTitle [1,2,3]  1 
MyTitle [1,2,3]  1  //not grouped by ...

Better than text, here's a graphgist I made to explain the issue, the workaround I found and what I really expect.

Does anyone know the reason? (maybe obvious...)

Mik378
  • 21,881
  • 15
  • 82
  • 180

1 Answers1

2

Just tried the following workaround: rebuild the array property as an collection:

RETURN extract(x in meeting.arrayProperty | x), count(participant) as number_part

Theory: the array property is handled as java native array whereas extract returns a collection (in Java sense). Comparing collections works based on comparing the elements whereas comparing a native array compares memory addresses which are different.

Stefan Armbruster
  • 39,465
  • 6
  • 87
  • 97
  • I don't think I figure out what doe mean your conclusion. May you explain further? – Mik378 Aug 09 '14 at 20:15
  • Why would a same array property be seen as several distinct memory adresses? – Mik378 Aug 09 '14 at 20:23
  • 1
    I guess under the hoods the `equals` method is used. However `Arrays.equals` should be used see http://stackoverflow.com/questions/8777257/equals-vs-arrays-equals-in-java. If you want to, file a github issue on https://github.com/neo4j/neo4j for this. – Stefan Armbruster Aug 10 '14 at 11:12
  • Ok, understood :) I'm using the workaround for the time being. – Mik378 Aug 10 '14 at 11:18
  • 1
    It's a bug in Cypher which has to be fixed, thanks for bringing it to attention – Michael Hunger Aug 11 '14 at 11:02
  • @MichaelHunger Ok :) No problem :) Should I have to create the ticket in Neo4j github (issue) or it's already taken into account? – Mik378 Aug 11 '14 at 11:11