Is Label Name in Gremlin Case Sensitive? - gremlin

Is Label Name in Gremlin Cosmos DB, Case Sensitive? For example is g.V().hasLabel('User') different with g.V().hasLabel('user')?

Yes. it is. You can test it by adding some instances to the database. For example:
g.addV('User');
g.addV('User');
g.addV('User');
Then get query by g.V().hasLabel('user'), the result will be null.

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.

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

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.

Gremlin code to find 1 vertex with specific property

I want to return a node where the node has a property as a specific uuid and I just want to return one of them (there could be several matches).
g.V().where('application_uuid', eq(application_uuid).next()
Would the above query return all the nodes? How do I just return 1?
I also want to get the property map of this node. How would I do this?
You would just do:
g.V().has('application_uuid', application_uuid).next()
but even better would be the signature that includes the vertex label (if you can):
g.V().has('vlabel', 'application_uuid', application_uuid).next()
Perhaps going a bit further if you explicitly need just one you could:
g.V().has('vlabel', 'application_uuid', application_uuid).limit(1).next()
so that both the graph provider and/or Gremlin Server know your intent is to only next() back one result. In that way, you may save some extra network traffic/processing.
This is a very basic query. You should read more about gremlin. I can suggest Practical Gremlin book.
As for your query, you can use has to filter by property, and limit to get specific number of results:
g.V().has('application_uuid', application_uuid).limit(1).next()
Running your query without the limit will also return a single result since the query result is an iterator. Using toList() will return all results in an array.

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