[Tinkerpop3] How to fetch the data from the step which is labeled in a map/filter lambda?

98 views
Skip to first unread message

Bharat Dighe

unread,
Aug 16, 2016, 1:40:48 PM8/16/16
to Gremlin-users
Hi,

here is the sample data

gremlin> g=TitanFactory.build().set("storage.backend", "inmemory").open();
==>standardtitangraph[inmemory:[127.0.0.1]]
gremlin> v1=g.addVertex("x", "1", "y","2");
==>v[4144]
gremlin> v2=g.addVertex("x", "2", "y","3");
==>v[4280]
gremlin> v1.addEdge("has", v2);
==>e[1l2-374-2dx-3aw][4144-has->4280]
gremlin> g.tx().commit();
==>null

Here is the traversal

gremlin> g.traversal().V().as("x");
==>v[4144]
==>v[4280]
gremlin> g.traversal().V().as("x").map{t->println(t.sideEffects("x").toString())}
gremlin>

Am I doing something incorrect here? Can the sideEffects provide data from labeled step?

Bharat

Daniel Kuppitz

unread,
Aug 16, 2016, 2:20:50 PM8/16/16
to gremli...@googlegroups.com
x is not a side-effect. Try this:

g.traversal().V().as("x").map{t->println(t.path("x").toString())}

Cheers,
Daniel


--
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-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/2ca9072b-de0b-466a-a81c-591dbda11099%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marko Rodriguez

unread,
Aug 16, 2016, 3:45:30 PM8/16/16
to gremli...@googlegroups.com
Hi,

Kuppitz, your traversal will fail because PATH requirement isn’t provided. Instead do g.traversal().withPath()…

Also, in general, don’t do g.traversal() every time. Instead:

graph = Titan…
g = graph.traversal()
g.withPath().V().as(…)
g.V()….
etc.

HTH,
Marko.
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/CA%2Bf9seVQMzoHKT8mNQLuC6aVeRxzRdh6RO%2B%3D_%2Bmwd%2BXjze3THQ%40mail.gmail.com.

Bharat Dighe

unread,
Aug 16, 2016, 6:51:23 PM8/16/16
to Gremlin-users
Thanks Guys.

This worked.
g.traversal().withPath().V().as("x").out().map{t->println(t.path("x").toString())}

Bhatat

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/2ca9072b-de0b-466a-a81c-591dbda11099%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kelvin Lawrence

unread,
Aug 27, 2016, 11:38:05 AM8/27/16
to Gremlin-users
Hi Marko, given you just showed a use case of where with Path() was needed to solve a user's question, might I suggest that an example be added to the Tinkerpop 3.2 docs. I just check the docs and other than in the API docs I could not see withPath() mentioned anywhere and even in the API docs there is zero English prose explaining it that I could see in a quick look.

Cheers
Kelvin
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/2ca9072b-de0b-466a-a81c-591dbda11099%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marko Rodriguez

unread,
Aug 27, 2016, 12:54:49 PM8/27/16
to gremli...@googlegroups.com
Hello,

It would be nice if we had a GraphTraversal Sources section like we have a GraphTraversal Steps section. There we would have:

withPath()
withSideEffect()
withSack()
withBulk()
withStrategies()
withoutStrategies()
etc.

…explained much like the we do for steps. If anyone would like to provide a pull request, I’d be more than happy to review, tweak, and graphic-out such a contribution.

Thanks,
Marko.

Stephen Mallette

unread,
Sep 2, 2016, 10:49:30 AM9/2/16
to Gremlin-users
I expanded the scope of an existing JIRA ticket as a reminder to handle the various with...() methods:


To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.

--
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-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/45EFB22B-4620-4380-8BB0-F9DD90C0E881%40gmail.com.

Bharat Dighe

unread,
Oct 4, 2016, 7:00:05 PM10/4/16
to Gremlin-users
Hi Marko,

How to use "withPath" with traversals which begins with a vertex.

__.__(v).has("type", "type1").as("x").out().map{t->println(t.path("x").toString())}

Thanks
Bharat


On Tuesday, August 16, 2016 at 12:45:30 PM UTC-7, Marko A. Rodriguez wrote:
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/2ca9072b-de0b-466a-a81c-591dbda11099%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marko Rodriguez

unread,
Oct 4, 2016, 7:38:25 PM10/4/16
to gremli...@googlegroups.com
You really should never use an anonymous traversal like that as you don’t get any strategies applied to it. You should do:

g.withPath().V(v).has("type", "type1").as("x").out().map{t->println(t.path("x").toString())}

HTH,
Marko.

Bharat Dighe

unread,
Nov 7, 2016, 1:07:02 AM11/7/16
to Gremlin-users
I am observing, when withPath() is used, it does not make use of index. Anything I am missing here?
(Should I post in titan google group?)

==>com.thinkaurelius.titan.graphdb.database.management.TitanGraphIndexWrapper
gremlin
> titanMgmt.getGraphIndex("by_name").getFieldKeys();
==>name


public static void main(String[] args) {
BaseConfiguration conf = new BaseConfiguration();
conf.setProperty("storage.backend", "cassandra");
conf.setProperty("storage.hostname", "localhost");
conf.setProperty("storage.port", 9160);
conf.setProperty("cache.db-cache", false);
conf.setProperty("storage.cassandra.keyspace", "my_ks");

@SuppressWarnings("resource")
TitanGraph graph = TitanFactory.open(conf);
System.out.println("Without withPath() ..");
System.out.println(graph.traversal().V().has("name", "xyz").count().next().longValue());
System.out.println("with withPath() ..");
System.out.println(graph.traversal().withPath().V().has("name", "xyz").count().next().longValue());
graph.close();
}


Output:
Without withPath() ..
5
with withPath() ..
22:04:54,236  WARN StandardTitanTx:1262 - Query requires iterating over all vertices [()]. For better performance, use indexes
22:04:54,246  INFO ThriftKeyspaceImpl:745 - Detected partitioner org.apache.cassandra.dht.Murmur3Partitioner for keyspace my_ks
5

Thanks
Bharat
Reply all
Reply to author
Forward
0 new messages