Has anyone been able to determine the equivalent of Gremlin Skip in Azure Cosmos? It's not listed on Microsoft's documentation and I was thinking it's just outdated. I did try doing a query such as g.V().hasLabel('the_label').has('the_property', eq('the_value')).skip(some_number) and it errors out as such Unable to find any method 'skip'.
From your link in the Apache TinkerPop documentation:
The skip()-step is analogous to range()-step save that the higher end range is set to -1.
with these examples:
gremlin> g.V().values('age').order().skip(2)
==>32
==>35
gremlin> g.V().values('age').order().range(2, -1)
==>32
==>35
Related
I am issuing Gremlin queries to a AWS Neptune database as follows:
client = Client(f"wss://{self.host}:{self.port}/gremlin", "g")
client.submit("g.V()...")
This works fine and I get the expected results.
I would like to include a SubgraphStrategy when issuing these queries. (I'm using a SubgraphStrategy to ignore nodes marked as deleted.) I can do this when I build the query dynamically, like this:
g = traversal().withRemote(remoteConn).withStrategies(
SubgraphStrategy(
vertices=__.hasNot("is_deleted"), edges=__.hasNot("is_deleted")
)
)
g.V()...
I cant figure out how to specify the subgraph strategy when issuing the query as a string. For example, I've tried this:
client = Client(f"wss://{self.host}:{self.port}/gremlin", "g")
client.submit('g.withStrategies(SubgraphStrategy.build().vertexProperties(hasNot("is_deleted")).V()...')
Does anybody know how to do this?
Neptune doesn't allow for that Java syntax that uses .build() when creating strategies, but I think it will support the Groovy syntax that was introduced at TinkerPop 3.4.9:
g.withStrategies(ReadOnlyStrategy,
new SubgraphStrategy(vertexProperties: __.hasNot('endTime')))
I have the following query which works without any issues with TinkerGraph, JanusGraph and Neo4j-Gremlin:
g.V().has('Account','address','0x0').
out('sent').has('eventName','Transfer').as('t1').
out('received_by').has('type','EOA').has('status','Active').as('a2').
out('sent').has('eventName','Transfer').as('t2').
where('t1',eq('t2')).by('address').
where('t1',eq('t2')).by('amount').
out('received_by').has('type','EOA').has('status','Active').as('a3').
select('a3','a2').
by('address').
group().
by('a3').
by('a2').
unfold().
where(select(values).limit(local,2).count(local).is(gte(2).and(lte(1000))))
But with DataStax Graph I get the following error:
java.util.LinkedHashMap cannot be cast to org.apache.tinkerpop.gremlin.structure.Element
I know the issue is after the select but I haven't been able to figure out in which point is really failing. Any ideas would help. Thanks.
DataStax Graph 6.8.1 uses an early release of TinkerPop 3.4.5. That release does not contain the full release feature that allows by(String) to work on a Map. You should be able to re-write your traversal to:
g.V().has('Account','address','0x0').
out('sent').has('eventName','Transfer').as('t1').
out('received_by').has('type','EOA').has('status','Active').as('a2').
out('sent').has('eventName','Transfer').as('t2').
where('t1',eq('t2')).by('address').
where('t1',eq('t2')).by('amount').
out('received_by').has('type','EOA').has('status','Active').as('a3').
select('a3','a2').
by('address').
group().
by(select('a3')).
by(select('a2').fold()).
unfold().
where(select(values).limit(local,2).count(local).is(gte(2).and(lte(1000))))
In this very simple example I am trying to add a new vertex which should be labeled like an existing vertex but with some prefix attached:
g.V(1).addV('prefix_' + label()).valueMap(true)
What am I missing here? It's clearly not a String, but how would I serialize that?
gremlin> g.V(1).label()
==>Person
gremlin> g.V(1).constant(label())
==>[LabelStep]
Gremlin today does not provide a built in string concatenation function. It would be nice if it did. That means your best alternative today is to use an in line closure/lambda. Here is an example using TinkerGraph and the air-routes graph.
gremlin> g.V(3).map {"prefix_" + it.get().label}.as('a').addV(select('a'))
==>v[60867]
gremlin> g.V(60867).label()
==>prefix_airport
Note that not all graph databases allow closures so this cannot be assumed to work universally on any TinkerPop enabled Graph DB backend.
Using the gremlin console connected remotely to a Neptune DB instance, I am grabbing all edges with a specific label and want to sort them by the id of the out vertex. I'm getting this error: "code":"UnsupportedOperationException","detailedMessage":"com.amazon.neptune.storage.volcano.ast.CutoffNode cannot be cast to com.amazon.neptune.storage.volcano.ast.AbstractGroupNode".
Sample data:
g.addV('user').property(id,'1').
addV('content').property(id,'2').
addE('history').property('val',9).from(g.V('1')).to(g.V('2'))
Queries and outputs:
g.E().hasLabel('history').order().by('val')
==>e[3][1-history>2]
g.E().hasLabel('history').outV().id()
==>1
g.E().hasLabel('history').order().by(outV().id())
{"requestId":<stuff>,"code":"UnsupportedOperationException","detailedMessage":
"com.amazon.neptune.storage.volcano.ast.CutoffNode cannot be cast to
com.amazon.neptune.storage.volcano.ast.AbstractGroupNode"}
I expect the result of that last one to be the same as the first. I've tried the same traversal in a TinkerGraph and didn't get an error, so judging by that and the message it's specifically a Neptune problem. Googling hasn't brought up anything.
Is there a traversal that will do what I'm looking for? What am I doing wrong?
I will look into why the error is being thrown but in the near term I think this workaround should work. Please let me know if it does not.
g.E().order().by(identity().outV().id())
Cheers,
Kelvin
In gremlin-console, is there a way to show all the methods available for a specific object?
For example, In gremlin-console if I type g.V().hasLabel("person") and I want to see what methods I can chain/call for the object returned by g.V().hasLabel("person"). How do you do that?
The answer is to use the <Tab> key.
gremlin> "test".c
capitalize() center( charAt( chars() codePointAt( codePointBefore( codePointCount( codePoints() collectReplacements( compareTo(
compareToIgnoreCase( concat( contains( contentEquals( count(
However, I'm finding that it is not working for something like g.V().o which I'd hoped would have shown out(). Apparently, the groovy shell (which is what the Gremlin Console is based on) doesn't seem to want to do the auto-complete on a fluent API. It seems to only work on the first object on which you are calling the method:
gremlin> g.
E( V( addV( addV() close() inject( tx() withBindings( withBulk(
withComputer( withComputer() withPath() withRemote( withSack( withSideEffect( withStrategies( withoutStrategies( anonymousTraversalClass
bytecode graph strategies
gremlin> x = g.V();[]
gremlin> x.o
option( optional( or( order( order() otherV() out( outE( outV()
gremlin> x.o
That stinks...that's not really a TinkerPop issue - we rely on the groovysh for that functionality. Not much we can do there I don't think....
Of course, you are using DSE Graph which means you have access to DataStax Studio which not only has the auto-complete that you're looking for but also schema support (and more!). I'd suggest that you switch to that.