Optimizing Gremlin Query for Neptune outV() inV() - gremlin

I'm new to gremlin and I'm trying to optimize the query.
Any ideas what can be done?
traversal = graph.V(fromID).toE(toID)
traversal.project(1KEY, 2KEY)
.by(valueMap().with(WithOptions.tokens))
.by(outV().valueMap().with(WithOptions.tokens))
.by(inV().valueMap().with(WithOptions.tokens));

Related

Convert gremlin query compatible with CosmosDB

Could you please help me to convert this query into a gremlin query compatible with CosmosDB? Unfortunately, I am getting Gremlin op does not support by(traversal) and looks like to be due to the version of Gremlin in CosmosDB.
Thank you.
Query
g.V().limit(10)
.dedup()
.as('node')
.project('id', 'label', 'properties', 'edges')
.by(__.id())
.by(__.label())
.by(__.valueMap().by(__.unfold()))
.by(
__.outE()
.project('id', 'from', 'to', 'label', 'properties')
.by(__.id())
.by(__.select('node').id())
.by(__.inV().id())
.by(__.label())
.by(__.valueMap().by(__.unfold()))
.fold()
)
It appears that from that error message that a by with a Traversal inside it is not supported. So something like by(outE()....) is likley one of the issues. I am not super familiar with the Gremlin support that CosmosDB offers but they do document their support differences here.
You will need to figure out which Gremlin constructs are supported in order to re-write the query. I am not sure if elementMap is supported, but if it is, that may be helpful in terms of getting the information about edges.

Gremlin OLAP traversal query error regarding local star-graph

I'm trying to execute an OLAP traversal on a query that needs to check if a vertex has a neighbour of certain type.
i keep getting
Local traversals may not traverse past the local star-graph on GraphComputer
my query looks something like:
g.V().hasLabel('label1').
where(_.out().hasLable('label2'))
I'm using the TraversalVertexProgram.
needless to say, when running the same query in oltp mode there is no problem
is there a way to execute such logic?
That is limitation of TinkerPop OLAP GraphComputer. It operate on 'star-graph' objects. The vertex and connected edges only. It uses message passing engine inside. So you have to rewrite you query.
Option 1: start from label2 and go t label1. This should return the same result
g.V().hasLabel('label2').in().hasLabel('label1')
Option2: try to use unique edge labels and check edge label instead
g.V().hasLabel('label1').where(_.outE('label1_label2'))

Azure Cosmos Graph DB Compound Conditional Query

Using Azure's Cosmos DB Graph Database I have a sample DB:Sample Graph Database. I am trying to expand a simple query into one that returns all the "Person" Nodes that have a "Skill Ratings" Node where MS_OFFICE=FAIL AND .NET=TRUE.
Current Query Thus Far:
ENGLISH DESCRIPTION: Find "Person Nodes" whose "Skill Ratings" Node match MS_OFFICE=FAIL
GREMLIN QUERY: g.V().hasLabel("Person").as("PersonNode")
.out("scored").as("SkillNode")
.has("skill_Name","MS_OFFICE")
.has("skill_Value","FAIL")
.select("PersonNode").by("Name")
To modify the existing query to include a conditional element, I was wondering if I am just missing a specific traversal step in the TinkerPop Documentation?
I think you just need something like this:
g.V().hasLabel("Person").
where(out("scored").
has("skill_name","MS_OFFICE").
has('skill_value","FAIL")).
values('name')

Updating node on Orientdb with gremlin query

I am having trouble updating properties in the nodes in Orientdb using gremlin with the following code. Both property and setProperty doesn't seem to work for OrientDB.
g.V('#rid','#100').property('text','new updated text'))
g.V('#rid','#100').setProperty('text','new updated text'))
However, I was able to update the node using SQL-like query that OrientDB supports.
update classname set text = 'new updated text' where #rid = #100
But I need to update the nodes with using gremlin query in OrientDB. I looked into gremlin query tutorials and most suggest that .property('text','new updated text') should work.
Is it that OrientDB only supports limited gremlin queries and not all?
You seem to have a bit of a mix between TinkerPop 2.x and 3.x syntax. My memory is really hazy about TinkerPop 2.x but I think you just need to iterate your traversal and use the second syntax. Therefore, assuming g.V('#rid','#100') returns a vertex you should just do:
g.V('#rid','#100').next().setProperty('text','new updated text'))

Check successful loading of data into cassandra by gremlin

I have setup my cassandra and titan running. And gremlin also works fine. I have connected gremlin to cassandra using,
gremlin>conf=new BaseConfiguration();
gremlin>conf.setProperty('storage.backend','cassandra');
gremlin>conf.setProperty('storage.hostname', '192.168.14.129');
gremlin>conf.setProperty('storage.keyspace','test');
gremlin>g=TitanFactory.open(conf);
And i have created a vertex,
gremlin> v1 = g.addVertex(label,"person","f_name","Anna");
==>v[8424]
How do i check if this data is entered into cassandra in test keyspace(already in cassandra)?
TinkerPop v3.x distinguishes between a Graph and a TraversalSource.
You should be doing the following only once:
graph = TitanFactory.open(conf)
g = graph.traversal()
Then execute all your traversals with:
g.V().some(...).gremlin(...).steps(...)
To find a Vertex by its id in Titan, you may have to cast the id to a Long. Assuming a Vertex with id 8424l, you can do:
g.V(8424l) // returns a traversal
g.V(8424l).next() // returns that vertex
You shouldn't be calling graph.traversal() more than once, as you get a performance hit every time. In the default Titan v1.0.0 setup, notice how the traversal initialization is done when starting Gremlin server (see conf/gremlin-server/gremlin-server.yaml which executes the scripts/empty-sample.groovy file).
According to your comment underneath here you want to retrieve the just added vertex. Please refer to the Tinkerpop reference. Using your g as notation for the graph it's simple as
gremlin> g.traversal().V(8424)
For getting the properties of the vertex read valueMap step in the reference. For obtaining the vertex not by its Id, but by its properties read has step. Be aware that I linked to the reference for Tinkerpop 3.2.0. You might chose a different version of that document to meet your very version of the stack.

Resources