Remove or replace id with entityId in gremlin response - azure-cosmosdb

Using Strategy I'm able to transform g.V(id) to g.V().has("entityId", id)
But is there a way I can remove id from gremlin output or replace it with entityId?
Without making changes at the serializer level?

Related

How to return only the id of a vertex in Cosmos Graph

I am importing data from SQL Server to Cosmos Gremlin Graph. During the process, I need to search for a vertex by its old id, as the new id is needed to create an edge. I only want the id not all the other properties.
I found the answer.
You can use the SubmitWithSingleResultAsync( query ); method with a query like g.V().has('elementTypeId','1').has('importId',123456).properties('id').value()

Gremlin: property name with static and dynamic

I'm trying create a property of vertice with static and dynamic value using selected properties. Here the code:
g.V('%s').as('source')
.until(or(hasLabel('target').has('v', '1'),loops().is(10)))
.repeat(__.in())
.outE('e').as('edge')
.inV().as('u')
.select('source')
.property(single, 'v', '1')
.property(single, union(constant('p_'),select('u').id()), select('e').properties('r').value())
This query is to copy property of edges as value and id of vertice as name of property with prefix 'p_'. The copy works, but the property name does not works, it's saving just prefix 'p_'.
Any ideas about this behaviour? I'm using tinkerpop 3.4.3, same the Neptune version.
Thanks!
The union() step in this traversal will not return a concatenation of the prefix and the property as you are hoping. Instead, it will return a single traverser for each item in the union(). In this case one containing "p_", one containing the id(), and one containing the "r" property.
Unfortunately, Gremlin does not have a string concatenation function that will accomplish this for you. See this below:
Concatenate Gremlin GraphTraversal result with string
As you are using Neptune the proposed solution in that answer will not work either as Neptune does not support lambdas in a traversal. Unfortunately, in this scenario the best way to accomplish this is likely to return the data to your application, concatenate the strings, and then update the property.

How to use the Partition Key in CosmosBD via SDK or via Select QUERY

Consider Below is my sample json.
{
"servletname": "cofaxEmail",
"servlet-class": "org.cofax.cds.EmailServlet",
"init-param": {
"mailHost": "mail1",
"mailHostOverride": "mail2"
}
i have chosen "servletname" as my primary key as i will receive it in every request plus few 1000 server names are there it could be the best PK.
My Question is, to make the partition key work for me.
Do i have to specify the partition key option seperately like below
ItemResponse<ServerDto> ServerDtoResponse = await this.container.ReadItemAsync<ServerDto>(bocServerDto.mailHost, new PartitionKey(bocServerDto.servletname));
or
Including the partition key in the select query itself , without adding seperate new PartitionKey(), like
select * from r where r.servletname='cofaxEmail' and r.mailHost='mail1';
Crux of the question is: By passing partitionKey object in where condition of select query is it enough to utilize the partition key feature?
Thanks
For any crud operation you would pass in the value for the partition key. For example, on a point read.
ItemResponse<ServerDto> ServerDtoResponse = await this.container.ReadItemAsync<ServerDto>(bocServerDto.mailHost, new PartitionKey("cofaxEmail"));
For a query, you can either pass it in the queryRequest options or use it in the query as the first filter predicate. Here is an example of using the queryRequest options.
thanks.

Tinkerpop Gremlin group by key and get latest

I am creating 2 users(uid=1 & uid=2) with 2 versions each.
g.addV('user1').property('uid',1).property('version',1)
.addV('user1').property('uid',1).property('version',2)
.addV('user1').property('uid',2).property('version',1)
.addV('user1').property('uid',2).property('version',2)
I want to get the latest version from each uid, I am using the uid as a groupBy key and getting the latest as shown
g.V().hasLabel('user1')
.group().by('uid').by(fold().order(Scope.local).by('version', Order.desc).unfold().limit(1)) //GraphTraversal<Vertex,Map<Object, Object>>
.flatmap(t -> t.get().values().iterator()) // convert to GraphTraversal<Vertex, Vertex>
//traverse out and get the path
.out('friend').path().by(elementMap())
Is the best approach for this requirement?
What would be the gremlin preferred way to convert the Map to a Vertex inside the flatmap rather than using the lambda? Suppose I want to add further steps after this.
Appreciate any help!
The group step has two modes. Without a label it acts as a barrier but with a label it acts as a side effect. You can have results flow through a group using your data as follows.
gremlin> g.V().group('x').by('uid').by(values('version').max())
==>v[42306]
==>v[42309]
==>v[42312]
==>v[42315]
==>v[42318]
gremlin> g.V().group('x').by('uid').by(values('version').max()).cap('x')
==>[1:2,2:2]
You can add more traversal steps of course before you decide what you want to do with the group. Such as:
g.V().group('x').by('uid').by(values('version').max())out()...

Objectify projection query with id as well in the result

How should a projection query be written in objectify, such that, the id of the entity also comes along in the result? (Projection query because my table has a lot of columns)
The query that I've written is
ofy().load().type(Item.class).filter("shopId",shopId)
.filter("name >=",name)
.filter("name <=",name+"\ufffd")
.order("-creationTime")
.project("name","imageUrl").list();
I've read putting id in the project function doesn't work. What's the workout to it, so that I get the name, imageUrl and the id as well?
My bad. The id does come along in the result. You don't need to put id in the project function.

Resources