Hash-as-UUID DTL function providing a simulated consistent UUID
PlannedIn CIM and other datamodels UUIDs are frequently used as identifiers, especially in XML-based datamodels.
Normally one would like to have a database of entities with their UUID so that one can use these in a consistent manner. The nature of "generating a UUID" is a different usecase, where the UUID will be unique and "random" to avoid any collisions. Currently the Sesam DTL can generate a UUID.
To avoid needing a dedicated storage/database for UUID mappings, I propose to include a "uuidhash" DTL function which will take a string (bytes - i.e could be integers, floats or any datatype via sprintf or similar) and produce a valid UUID based on a hash of that string. Repeated calls to the function with the same string would produce the same UUID, in a similar fashion to looking up a UUID from a database which is the conventional usecase and practice. For performance and ease-of-development a function is much faster and similarly useful when the hashing function is cryptographic in nature.
Example usage in DTL:
```
default": [
["copy", "*"],
["add", "my-uuid",
["uuidhash", "_T._id"]
],
["add", "rdf:type",
["ni", "namespace", "typename"]
]
]
```
The above example will hash the entity ID and produce a valid UUID-formatted string where the hash is truncated to 16 first octets and the correct bits are set according to UUID version 4.
See also:
- https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_(random)
```
default": [
["copy", "*"],
["add", "rdf:type",
["ni", "namespace", "typename"]
],
["add", "my-uuid",
["uuidhash", "_T.rdf:type", ["ni-id", "_T._id"]]
],
]
```
The above example would create a UUID version 4 from a string formatted according to sprintf("%s:%s", namespace, string).
In both examples the returned value from the "uuidhash" function would be a canonical 8-4-4-4-12 format string. Perhaps there could also be a 128bit integer or byte-buffer output without the canonical format, but that is less important for the most common usecase of e.g XML and other outputs.
Please sign in to leave a comment.
Comments
0 comments