Get both label and property

2,530 views
Skip to first unread message

HadoopMarc

unread,
Oct 4, 2016, 10:22:22 AM10/4/16
to Gremlin-users
Hi all,

is there anythging shorter for getting both label and property, than:

gremlin> g.V().as('a').label().as('b').select('a').values('name').as('c').select('b','c').select(values)
==>[person, marko]
==>[person, vadas]
==>[software, lop]
==>[person, josh]
==>[software, ripple]
==>[person, peter]

I tried

gremlin> g.V().values(label(), 'name')
Could not complete query => startup failed: Script22.groovy: 1: [Static type checking] - Cannot call <E2> org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal <org.apache.tinkerpop.gremlin.structure.Vertex, org.apache.tinkerpop.gremlin.structure.Vertex>#values(java.lang.String[]) with arguments [org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal <A extends java.lang.Object, java.lang.String>, java.lang.String] @ line 1, column 1. g.V().values(label(), 'name' ) ^ 1 error (Error 597)

or even

gremlin> g.V().identity().by(label()).by('name')
Could not complete query => org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep cannot be cast to org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent (Error 597)

but to no avail. Do I miss something?

Cheers,      Marc

Marko Rodriguez

unread,
Oct 4, 2016, 10:29:14 AM10/4/16
to gremli...@googlegroups.com
Hmmm… yea, its sorta ghetto.

g.V().union(label(),values('name'))

gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V().union(label(),values('name'))
==>person
==>marko
==>person
==>vadas
==>software
==>lop
==>person
==>josh
==>software
==>ripple
==>person
==>peter
gremlin>

I also wish there was something better than valueMap(true). :|

Perhaps values() should also take T. ?? — values(label,’name’) … :/


Marko.
--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/e7ea3a82-7c0c-471d-9bfc-c95ff3030f94%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

HadoopMarc

unread,
Oct 4, 2016, 11:39:11 AM10/4/16
to Gremlin-users
Hi Marko,

OK, thanks. values(label,’name’) is indeed what I expected and tried, but did not work.

Project looks promising, although I am still on TP3.1.x

Cheers,    Marc

Op dinsdag 4 oktober 2016 16:29:14 UTC+2 schreef Marko A. Rodriguez:

HadoopMarc

unread,
Oct 4, 2016, 3:15:09 PM10/4/16
to Gremlin-users
Hi Marko (again),

Indeed on TP3.2 the project step alternative works:

gremlin> g.V().project('a','b').by('name').by(label).select(values)
==>[marko,person]
==>[vadas,person]
==>[lop,software]
==>[josh,person]
==>[ripple,software]
==>[peter,person]

Also,
gremlin> g.V().values('name','age') gives:
==>marko
==>29
==>vadas
==>27
==>lop
==>josh
==>32
==>ripple
==>peter
==>35

So,even if g.V().values(label, 'age') were allowed, it would not give the result you can get with project(); no issue left.

Cheers,    Marc



Op dinsdag 4 oktober 2016 17:39:11 UTC+2 schreef HadoopMarc:

Daniel Kuppitz

unread,
Oct 4, 2016, 3:23:14 PM10/4/16
to gremli...@googlegroups.com
This should work in older versions:

g.V().map(union(label(), values("name")).fold())

It's even shorter than the project() query.

Cheers,
Daniel


To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/4e398430-80e1-44ee-8a3e-e27a8e028c50%40googlegroups.com.

HadoopMarc

unread,
Oct 4, 2016, 3:50:55 PM10/4/16
to Gremlin-users
Hi Daniel,

Beautiful, again, thanks!

But then: g.V().map( values(label, 'name').fold() ) would make sense too.   See: group().by('name') and group().by(label) are possible, but values(label, 'name') not.

Cheers,     Marc

Op dinsdag 4 oktober 2016 21:23:14 UTC+2 schreef Daniel Kuppitz:
Reply all
Reply to author
Forward
0 new messages