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.
Related
On an Azure cosmosDB gremlin instance,
I have 2 vertices A and B linked by and edge E.
Both vertices has a 'name' property.
I'd like to run a query which will take A's name and put it in B
when I run
g.V("AId").as("a").oute().inv().hasLabel('B').property("name",select('a').values('name'))
I get the following error :
GraphRuntimeException ExceptionMessage : Gremlin Query Execution Error: Cannot create ValueField on non-primitive type GraphTraversal.
It looks like the select operator is not correctly used.
Thank you for your help
EDITED based on discussion in comments
You have oute and inv in lower case. In general, the steps use camelCase naming, such as outE and inV (outside of specific GLVs), but in the comments it was mentioned that CosmosDB will accept all lower case step names. Assuming therefore, that is not the issue here, the query as written looks fine in terms of generic Gremlin. The example below was run using TinkerGraph, and uses the same select mechanism to pick the property value.
gremlin> g.V(3).as("a").outE().inV().has('code','LHR').property("name",select('a').values('city'))
==>v[49]
gremlin> g.V(49).values('name')
==>Austin
What you are observing may be specific to CosmosDB and it's probably worth contacting their support folks to double check.
Based on this answer provided by daniel-luppitz, I am trying to clone a vertex in Azure CosmosDb but I am getting the following error:
Compilation Error: Unable to bind to method 'property', with arguments of type: (GraphTraversal,GraphTraversal)
The query:
IGraphTraversalSource g = coreClient.CreateTraversalSource();
ITraversal query = g.V(new PartitionKeyIdPair(pk, id)).As("source")
.AddV("clone").Property("partitionKey", pk).As("clone")
.SideEffect(__.Select<User>("source").Properties<String>().As("p").Select<User>("clone")
.Property(__.Select<object>("p").Key(), __.Select<string>("p").Value<string>()))
If I change the key and value traversals
.Property(__.Select<object>("p").Key(), __.Select<string>("p").Value<string>()
to constant values then the query works
.Property("test", "test")
Any idea how to achieve this in Azure CosmosDb?
I'm not sure which TinkerPop version is currently supported by Cosmos DB, but after skimming through the docs, I would say it's something close to 3.2.5. The 3.2 line did not support dynamic keys/values, that was added somewhere along the 3.3 line.
Thus, the only way to do that in Cosmos DB would be to split the query. Get the values you need and then submit follow-up queries based on the gathered values. Obviously, this won't perform very well will probably increase your usage costs dramatically, but I can't think of another way of doing it using old Gremlin versions (considering that lambdas are another thing that's not supported in Cosmos DB).
I cannot select a specific vertex, by executing g.V(3640).valueMap(true).unfold(). Any command which contains an ID between the parentheses in the g.V() command does not seem to work.
This is what I did:
I'm new to Graph databases and experimenting with the Gremlin console. I started by creating an instance:
graph = TinkerGraph.open()
g=graph.traversal()
and loading sample data by importing a .graphml database file:
g.io(graphml()).readGraph('/full/path/to/air-routes-latest.graphml')
which seemed to work fine because a count gives a nice result back
gremlin> g.V().count()
==>3642
Unfortunately the following does not work:
gremlin> g.V(3640).valueMap(true).unfold()
Which I think is odd, because by executing the following
gremlin> g.V()
==>v[3640]
==>v[2306]
...
the ID does seem to exist. Any ideas why I cannot access a specific ID? I tried different commands but g.V() seems to work fine, and g.V(3640) does not. Is it because I use TinkerGraph instead of a Gremlin database, of what might be the problem?
EDIT:
It seems that my id's were saved as strings, because g.V("2").valueMap(true).unfold() does give me results.
I think you likely have an issue with the "type" of the identifier. I suspect that if you do:
g.V(3640L)
that you will get the vertex you want. By default, TinkerGraph handles id equality with equals() so if you try to find an integer when the id is a long it will act like it's not there. You can modify that default if you like with an IdManager configuration discussed here. Note that this is also discussed in more detail in Practical Gremlin.
How is it possible to define some enumeration type (like java-enumeration) in janus-graph DB by gremlin query?
It seems that something like enum can be define by List typed property:
enumProperty = mgmt.makePropertyKey('State').dataType(String).cardinality(Cardinality.LIST).make()
Is there another way?
Ideally, I would like to be able to refer to these enumerated values (as in Java SomeEnum.ENUM_VALUE_1) when creating/updating the vertices/edges by gremlin queries.
You can create a LIST or SET cardinality property using pure Gremlin if you are working with a graph that does not have an explicit schema API. Here are a few examples
g.addV('test').property('p1','one').property('p1','two')
==>v[55985]
g.V(55985).valueMap()
==>[p1:[one,two]]
gremlin> g.V(55985).property(list,'p1','three')
==>v[55985]
gremlin> g.V(55985).valueMap()
==>[p1:[one,two,three]]
Hope this helps,
I have fairly detailed coverage of this concept in the book/tutorial which you can read for free here http://kelvinlawrence.net/book/Gremlin-Graph-Guide.pdf or here http://kelvinlawrence.net/book/Gremlin-Graph-Guide.html
Cheers
Kelvin
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'))