[Neo4j] Cypher with Array

897 views
Skip to first unread message

John Howard

unread,
Jan 22, 2012, 10:40:47 PM1/22/12
to Neo4j user discussions
Hello,

I am trying to get distict property values on a list of nodes.
The property value is an array in graph. Example:
node1.color = [red]
node2.color=[red]
node3.color=[green]
node4.color=[yellow]
node5.color=[red]

My cypher query:
START n=node:index(type="sometype")
RETURN distinct n.color,count(*)

it returns
[red]
[red]
[green]
[yellow]
[red]

Shouldn't it just return 3 unique colors?
if not how do I access just the first element of an array property value in
the RETURN statement (ex: RETURN distinct n.color[0]? ) ?

I am using Neo 1.6M03.

Thanks in advance,

John
_______________________________________________
NOTICE: THIS MAILING LIST IS BEING SWITCHED TO GOOGLE GROUPS, please register and consider posting at https://groups.google.com/forum/#!forum/neo4j

Neo4j mailing list
Us...@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user

Andres Taylor

unread,
Jan 23, 2012, 12:56:14 AM1/23/12
to Neo4j user discussions
On Mon, Jan 23, 2012 at 4:40 AM, John Howard <johny...@gmail.com> wrote:

> Hello,
>
> I am trying to get distict property values on a list of nodes.
> The property value is an array in graph. Example:
> node1.color = [red]
> node2.color=[red]
> node3.color=[green]
> node4.color=[yellow]
> node5.color=[red]
>
> My cypher query:
> START n=node:index(type="sometype")
> RETURN distinct n.color,count(*)
>
> it returns
> [red]
> [red]
> [green]
> [yellow]
> [red]
>
> Shouldn't it just return 3 unique colors?
>

This is not what happens when I try it here:


- neo4j-sh (0)$ start n=node(0,1,2,3,4) return distinct n.color, count(*)
- ==> +---------------------+
- ==> | n.color | count(*) |
- ==> +---------------------+
- ==> | "red" | 3 |
- ==> | "green" | 1 |
- ==> | "yellow" | 1 |
- ==> +---------------------+
- ==> 3 rows, 3 ms


How are you running your tests? How are you inserting data?

Andrés

John Howard

unread,
Jan 23, 2012, 1:06:27 AM1/23/12
to Neo4j user discussions
That's strange.
Did you load the property values as an array or just as string values?
Your output values show "red" where as mine ["red"].

This is my output:
neo4j-sh (0)$ START n=node:fulltextIndex(type="person") RETURN distinct
n.color?,count(*)
==> +-----------------------+
==> | n.color | count(*) |
==> +-----------------------+
==> | ["red"] | 1 |
==> | ["green"] | 1 |
==> | ["green"] | 1 |
==> | ["amber"] | 1 |
==> | ["red"] | 1 |
==> | ["red"] | 1 |
==> | ["red"] | 1 |
==> | ["green"] | 1 |
==> | ["amber"] | 1 |
==> | ["amber"] | 1 |
==> | ["green"] | 1 |
==> | ["green"] | 1 |
==> | ["green"] | 1 |
==> | ["red"] | 1 |
==> | ["red"] | 1 |
==> | ["green"] | 1 |
==> | ["amber"] | 1 |
==> | ["green"] | 1 |

Andres Taylor

unread,
Jan 23, 2012, 1:16:42 AM1/23/12
to Neo4j user discussions
On Mon, Jan 23, 2012 at 7:06 AM, John Howard <johny...@gmail.com> wrote:

> That's strange.
> Did you load the property values as an array or just as string values?
> Your output values show "red" where as mine ["red"].
>

Yeah, sorry. Didn't catch the array value part. You have found a bug!

https://github.com/neo4j/community/issues/193

Thanks so much for reporting this.

John Howard

unread,
Jan 23, 2012, 1:25:39 AM1/23/12
to ne...@googlegroups.com, Neo4j user discussions
Thanks Andres.
Is there a way I can access the value at index zero of an array in the
return clause.
something like, RETURN distinct n.color[0]

Andres Taylor

unread,
Jan 23, 2012, 2:11:56 AM1/23/12
to ne...@googlegroups.com, Neo4j user discussions
Nope - that's not possible today. Makes sense to have it though. Could you open an issue about it?

Andrés

John Howard

unread,
Jan 23, 2012, 2:50:16 PM1/23/12
to ne...@googlegroups.com, Neo4j user discussions

Andres Taylor

unread,
Jan 23, 2012, 2:55:12 PM1/23/12
to ne...@googlegroups.com


On Mon, Jan 23, 2012 at 8:50 PM, John Howard <johny...@gmail.com> wrote:
Here you go:

Thanks!

Andrés

John Howard

unread,
Jan 25, 2012, 9:21:20 PM1/25/12
to ne...@googlegroups.com
I see that this issue has been fixed.
Has it been released? If not how do I get the latest snapshot to test it out?
whats the link?

Thanks.

Andres Taylor

unread,
Jan 26, 2012, 12:47:19 AM1/26/12
to ne...@googlegroups.com
On Thu, Jan 26, 2012 at 3:21 AM, John Howard <johny...@gmail.com> wrote:
I see that this issue has been fixed.

Hi John,

Unfortunately, it has not been solved yet.

If you're curious, I want to find a way to express this, not only for properties, but for any iterable. 

Example: RETURN nodes(p)[0] 

I'm not happy with this, and that is one reason it's taking a little longer.

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