Updating node on Orientdb with gremlin query - graph

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'))

Related

Azure cosmosDB gremlin - how to update vertex property with another vertex's property

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.

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.

Azure CosmosDb Gremlin API, Clone vertex, Compilation Error

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).

Gremlin: Rollback the query if an exception occurs

I am trying to submit a batch like operation for creating multiple vertices and edges in the same query.
g.addV('os').property('name', 'linux').as('linux').
addV('os').property('name', 'windows').as('windows').
addV('os').property('name', 'mac').as('mac').
addE('competitor').from('linux').to('UNEXISTING OS'). # fail here
addE('competitor').from('linux').to('windows').
addE('competitor').from('windows').to('mac').
addE('competitor').from('linux').to('mac').
iterate()
The query is constructed to intentionally fail, however all vertices before the failing line are being created.
Is it possible to achieve a kind of transaction for the whole query? So that if one subquery fails, it should rollback the ones that were previously executed.
Thanks!
The query could not be executed in the Gremlin Console using TinkerGraph,
as per TinkerPop documentation, there isn't support for transactions for built-in TinkerGraph object.
But, as cygri pointed out, AWS Neptune offers support for transactions (see here), that can be executed under the form of original query from OP or by separating queries by a semicolon (;) or a newline character (\n)
g.addV('os').property('name', 'linux').next();
g.addV('os').property('name', 'windows').next();
g.addE('competitor').from('1101').to('1102')
You can also use Gremlin Sessions; create a sessioned-connection and it'll rollback queries in case of an error.

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')

Resources