fkleedorfer
fkleedorfer

Reputation: 606

How to generate UUIDs for updates via SPARQL

Using an RDF database, accessed via a SPARQL endpoint, what's the best way of generating new UUID IRIs and using them for new resources?

Here is an overview of some approaches I've tried. I am sharing this because I would have liked to find this question answered. My favourite is the last approach, but I'd say it's still up for debate.

Generate a UUID in the client and using it in the Update request

Generate a UUID in the client and check if the RDF store contains triples with that id. Iterate until the UUID is new.

Ask the RDF store for a UUID and use it

Query: SELECT (UUID() as ?id) WHERE{}

Ask the RDF store for N >> 1 UUIDs before doing a bigger amount of updates

Query (returns 1000 result rows):

SELECT (UUID() as ?id) WHERE {
   VALUES ?index1 { 0 1 2 3 4 5 6 7 8 9 } 
   VALUES ?index2 { 0 1 2 3 4 5 6 7 8 9 } 
   VALUES ?index3 { 0 1 2 3 4 5 6 7 8 9 } 
}

Related:

Upvotes: 0

Views: 315

Answers (1)

fkleedorfer
fkleedorfer

Reputation: 606

Following AndyS's comment, I decided to look that up again and adjust my expectations: you have to generate 1 billion UUIDs per second for about 85 years to reach a 50% probability of one or more collisions. Therefore, Variant 1 is best:

Generate a UUID in the client and use it in the update request.

Upvotes: 2

Related Questions