trinodb / trino

Official repository of Trino, the distributed SQL query engine for big data, formerly known as PrestoSQL (https://trino.io)
https://trino.io
Apache License 2.0
10.38k stars 2.98k forks source link

Add support for uuid 3 and uuid 5 functions #13273

Open aimran-adroll opened 2 years ago

aimran-adroll commented 2 years ago

The current version of UUID provides a random identifier (verion 4).

However, certain situations requires a more stable uuid (i,e version 5 or 3). Advantage with these UUIDs (v5 or v3) is that they have the property that the same namespace and name will map to the same UUID.

Its possible to have a facsimile (see example below) of uud5 but requires a awkward hand-crafted udf. It might be more convenient if it were a first class function instead.

Here is an example in snowflake that overloads uuid_string to provide either version 4 or 5

Thanks for your consideration and hard work


Contrast how uuid5 is namespace aware (and idempotent) compared to existing uuid function

trino> select substr(to_hex(sha256(from_base64url('this_is_a_my_namespace'||'__'||'my_actual_variable'))), 1, 32) as fake_uuid_5, uuid() as current_uuid;
           fake_uuid_5            |             current_uuid
----------------------------------+--------------------------------------
 C5871659322001D2B21C2A65069F0A6D | 344d8ea9-eaca-42a6-88d8-7a8ad2509bde

trino> select substr(to_hex(sha256(from_base64url('this_is_a_my_namespace'||'__'||'my_actual_variable'))), 1, 32) as fake_uuid_5, uuid() as current_uuid;
           fake_uuid_5            |             current_uuid
----------------------------------+--------------------------------------
 C5871659322001D2B21C2A65069F0A6D | bb9a41af-9597-43e7-926a-40291e64ca24
ebyhr commented 2 years ago

Does #4413 help you?

aimran-adroll commented 2 years ago

Thanks. That would certainly do it for me 🎉

Whatever happened to that PR though?