Ho to check if edge already exist before create one with gremlin query? How to update existing edge instead of deleting and recreating?
I'm not sure if you're still looking for an answer; however, the simple answer is that Cosmos DB is somewhat limited in its Gremlin support. See here: https://learn.microsoft.com/en-us/azure/cosmos-db/gremlin-support. The only way to update an edge as at the time of writing this answer is to delete and recreate the edge. That is true whether you're adding properties or updating them.
In terms of querying if the edge already exists, you can use g.E('<xyz-id-guid>') or g.V('id', '<xyz-id-guid>', '<partition-key-property>', '<xyz-id>').outE('<edge-label>').hasId('<xyz-id-guid>'). The hasId() part is optional but recommended as is the use of the partition key value. Both help performance.
Hope that helps.
Cheers,
Seb
Related
where is the document about gremlin with step?
https://tinkerpop.apache.org/docs/current/reference/#with-step
https://tinkerpop.apache.org/javadocs/current/full/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/ShortestPath.html
there is no example I can use.
I want to know all with-step option(like ShortestPath.edges-Direction.OUT) for shortestPath().
I found below
g.withComputer().V(xxx).shortestPath().with(ShortestPath.edges, Direction.OUT).with(ShortestPath.distance, 'cost').with(ShortestPath.target, hasId(bbb))
I want to know all option I can use
The with()-step is not really a "step". It is a step modulator. Its context is bound to the step that it is modifying and therefore you won't find "all the with() configurations" in one place. You can only find them in the documentation related to the steps that they modulate. Using shortestPath() as an example, note that if you look at the shortestPath() step documentation all of the options are present.
You may also need to consult the documentation of your graph provider as they may provide their own configuration keys for certain steps which can help optimize or otherwise modify traversal operations.
I don't want to provide a migration script while changing table schema in realm java. Also, app should not crash and all the previous data should be erased or truncated something similar to fallbackToDestructiveMigration() as room dose?
Realm provides RealmConfiguration.Builder().deleteIfMigrationNeeded()..., where deleteIfMigrationNeeded() does exactly what you are looking for.
Using Gremlin, I can create a vertex in an Azure Cosmos DB graph by issuing
g.addV('the-label').property('id', 'the-id')
and subsequently find it using
g.V('the-label').has('id', 'the-id')
However, I haven't found a way to issue a query that will insert the node if it is missing, and just get the reference to it if it already exists. Is there a way?
My concrete use case is that I want to add an edge between two nodes, regardless of whether those nodes (or the edge, for that matter) exist already or not, in a single query. I tried this upsert approach, but apparently Cosmos DB does not support Groovy closures, so it won't work.
The "upsert pattern" is relatively well defined and accepted at this point. It is described here. If you want to extend that to also add an edge, that's possible too:
g.V().has('event','id','1').
fold().
coalesce(unfold(),
addV('event').property('id','1')).as('start').
coalesce(outE('link').has('id','3'),
coalesce(V().has('event','id','2'),
addV('event').property('id','2')).
addE('link').from('start').property('id','3'))
If that looks a bit complex you can definitely simplify with a Gremlin DSL (though I'm not sure that CosmosDB supports Gremlin bytecode at this point). Here's an example with even more complex upsert logic simplified by a DSL. It's discussed in this blog post in more detail.
Please look at this.
http://tinkerpop.apache.org/docs/current/reference/#coalesce-step
You can try
g.Inject(0).coalesce(__.V().has('id', 'the-id'), addV('the-label').property('id', 'the-id'))
btw, you won't able to find the vertex using g.V('the-label').has('id', 'the-id').
g.V() accepts vertex id as parameters and not vertex labels.
I found this question How to store and retrieve different types of Vertices with the Tinkerpop/Blueprints graph API?
But it's not a clear answer for me.
How do I query the 10 most recent articles vs the 10 most recently registered users for an api for instance? Put graphing aside for a moment as this stack must be able to handle both a collection/document paradigm as well as a graphing paradigm (relations between elements of these TYPES of collections). I've read everything including source and am getting closer but not quite there.
Closest document I've read is the multitenant article here: http://architects.dzone.com/articles/multitenant-graph-applications
But it focuses on using gremlin for graph segregation and querying which I'm hoping to avoid until I require analysis on the graphs.
I'm considering using cassandr/hadoop at this point with a reference to the graph id but I can see this biting me down the road.
Indexes in Tinkerpop/Blueprints only support simple lookups based on exact matches of property keys.
If you want to find the 10 most recent articles, or articles with the phrase 'Foo Bar', you may have to maintain an external index using Lucene or Elastic Search. These technologies use inverted indexes which support term/phrase lookups, range queries, and wildcard searches, etc. You can store the vertex.getId() as the field in the indexed document to link back to the vertex in the graph database.
I have implemented something like this for my application which uses a Blueprints database (Bitsy) and a fancy index (Lucene). I have documented the high-level design to (a) keep the fancy index up-to-date using batch updates every few seconds and (b) ensure transactional consistency across the graph database and the fancy index. Hope this helps.
Answering my own question to this - The answer is indices.
https://github.com/tinkerpop/blueprints/wiki/Graph-Indices
I'm considering using SubSonic to create and access an SQLite database.
Not sure yet what flavor fits better for me though I tend to prefer the SimpleRepository approach.
Indeed I don't expect my DB to do much more than storing my objects and basic querying.
I've been through to docs but there are still a few points unclear to me or that I'd like to have confirmation for:
1/ Does "3.0 Migrations" fully support SQLite ?
2/ Using SimpleRepository, is the auto-migration feature equivalent to the 'regular' migration feature or does it support only a subset of it (apart from the incremental aspect) ?
3/ In particular, how can one specify a foreign key like it can be done with Migration.CreateForeignKey(TableColumn oneTable, TableColumn manyTable)?
I would love a [SubSonicForeignKey(Table, Column)] attribute to flag a property as such for helping relationship navigations and also indexing the column.
I suppose I'm dreaming, and the best solution I've found so far is like described in this post:
http://www.frozenmountain.com/blog/post/Automatic-Foreign-Objects-in-SubSonic3-SimpleRepository.aspx
4/ But this still can't address the missing index. So to the Subsonic Team: Any chance to see a [SubSonicIndex] attribute some day?
Thanks!