[Neo4j] Gremlin results questions (with SDN mapping)

49 views
Skip to first unread message

Marc de Verdelhan

unread,
Mar 13, 2012, 12:41:47 PM3/13/12
to ne...@googlegroups.com
Hello graphdb users,

2 questions:

=== (1) Gremlin + SDN interaction ===

I have a NodeEntity named "Project" like this:
@NodeEntity
public class Project {
@GraphId Long internalId;
@Indexed(unique=true) String id;
public Project(String id) {
this.id = id;
}
}
I want to get the id through Gremlin: @Query(value="g.v(project).id", type=QueryType.Gremlin) ... but it returns the internal id. How could I get the id I set in the constructor?

=== (2) Gremlin only. ===

Now I want to detect loops. So I wrote the following query: g.v(project).in('REL_A').out('REL_B').loop(2){(it.object != g.v(project)) && (it.loops < 4)}{it.object == g.v(project)}.paths

It returned:
[v[30], v[32], v[31], v[28], v[30]]
[v[30], v[32], v[31], v[28], v[27], v[25], v[24]]
[v[30], v[32], v[31], v[28], v[27], v[25], v[26]]
Why does it return the 2 last paths? According to me it should not...

Even if I put false in the emit closure (g.v(project).in('REL_A').out('REL_B').loop(2){(it.object != g.v(project)) && (it.loops < 4)}{false}.paths), I get the same result.

Thank you for answerers to come and for your clarifications.

Regards,

MV

Peter Neubauer

unread,
Mar 13, 2012, 12:44:19 PM3/13/12
to ne...@googlegroups.com
Hi there,
this might be a shadowing issue, could you name your own ID
differently and check things?

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

Neo4j 1.6 released                 - dzone.com/6S4K
The Neo4j Heroku Challenge   - http://neo4j-challenge.herokuapp.com/

Marko Rodriguez

unread,
Mar 13, 2012, 12:45:10 PM3/13/12
to ne...@googlegroups.com
Hi,

=== (2) Gremlin only. ===

Now I want to detect loops. So I wrote the following query: g.v(project).in('REL_A').out('REL_B').loop(2){(it.object != g.v(project)) && (it.loops < 4)}{it.object == g.v(project)}.paths

It returned:
[v[30], v[32], v[31], v[28], v[30]]
[v[30], v[32], v[31], v[28], v[27], v[25], v[24]]
[v[30], v[32], v[31], v[28], v[27], v[25], v[26]]
Why does it return the 2 last paths? According to me it should not...

Even if I put false in the emit closure (g.v(project).in('REL_A').out('REL_B').loop(2){(it.object != g.v(project)) && (it.loops < 4)}{false}.paths), I get the same result.

You are using Gremlin 1.4 is sounds like. Since 1.5, the emit/loop closures have a bit of different semantics where if the emit closure is provided, then that is the ONLY source of emissions from the loop [see Pipes 1.0  release notes https://github.com/tinkerpop/pipes/wiki/Release-Notes]. With Gremlin 1.4, what is happening is that you are emitting from the emit-closure as well as those things that break out of the loop. So, in some instances, its repeating elements.

Marko.

Marc de Verdelhan

unread,
Mar 15, 2012, 5:45:51 AM3/15/12
to ne...@googlegroups.com
SDN Jira ticket added: https://jira.springsource.org/browse/DATAGRAPH-211

Cheers,

MV

On Wed, Mar 14, 2012 at 3:18 PM, Marc de Verdelhan <marc.dev...@yahoo.com> wrote:
@Peter,

Ok it seems there is a bug on IDs with SDN(2.1.0.M1)/Gremlin(1.4).

First version:
@NodeEntity
public class Project {
@GraphId Long internalId;
@Indexed(unique=true) String id;
public Project(String id) {
this.id = id;
}
}
With a "new Project("p019");" I get:
g.v(project).keys() --> [id, __type__]
g.v(project).id --> 29 (the internal id, not the one I set)

Second version:
@NodeEntity
public class Project {
@GraphId Long internalId;
@Indexed(unique=true) String pid;
public Project(String pid) {
this.pid = pid;
}
}
With the same "new Project("p019");" I get:
g.v(project).keys() --> [pid, __type__]
g.v(project).pid --> "p019"

@Marko,
Ok I think I'm going to upgrade to Gremlin 1.5. I'll just wait for Neo4j 1.7.M1 and a SDN adaptation.

Thank you.

MV

Marc de Verdelhan

unread,
Mar 14, 2012, 10:18:42 AM3/14/12
to ne...@googlegroups.com
@Peter,

Ok it seems there is a bug on IDs with SDN(2.1.0.M1)/Gremlin(1.4).

First version:
@NodeEntity
public class Project {
@GraphId Long internalId;
@Indexed(unique=true) String id;
public Project(String id) {
this.id = id;
}
}
With a "new Project("p019");" I get:
g.v(project).keys() --> [id, __type__]
g.v(project).id --> 29 (the internal id, not the one I set)

Second version:
@NodeEntity
public class Project {
@GraphId Long internalId;
@Indexed(unique=true) String pid;
public Project(String pid) {
this.pid = pid;
}
}
With the same "new Project("p019");" I get:
g.v(project).keys() --> [pid, __type__]
g.v(project).pid --> "p019"

@Marko,
Ok I think I'm going to upgrade to Gremlin 1.5. I'll just wait for Neo4j 1.7.M1 and a SDN adaptation.

Thank you.

MV

On Tue, Mar 13, 2012 at 5:45 PM, Marko Rodriguez <okram...@gmail.com> wrote:

Michael Hunger

unread,
Mar 15, 2012, 4:20:02 PM3/15/12
to ne...@googlegroups.com
This is not a bug in SDN, it stores your id field as "id" property in Neo4j, 
you should use v.getProperty("id") in gremlin in this case (which is also faster than v.id).

Marc de Verdelhan

unread,
Mar 16, 2012, 4:13:29 AM3/16/12
to ne...@googlegroups.com
@Michael,

Thank you very much for that explanation.
This behavior appeared to me weird. Sorry for the misunderstanding.

Cheers,

MV

Marko Rodriguez

unread,
Mar 16, 2012, 12:09:15 PM3/16/12
to ne...@googlegroups.com
Hi,

Just to be safe, note that Blueprints does not allow you to have the property 'id' on elements (vertices/edges). Moreover, on an edge, you can not have the property 'label.'

HTH,
Marko.
Reply all
Reply to author
Forward
0 new messages