-
Notifications
You must be signed in to change notification settings - Fork 3.4k
WIP: Add uuid_v6 and uuid_v7 functions #27493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Before I start adding tests and whatnot, let's agree on naming first. @martint can you take a look? |
| @Constraint(variable = "u", expression = "min(u, 6)") | ||
| public static Slice uuid_v6(@SqlType("timestamp(u) with time zone") long rawTimestamp) | ||
| { | ||
| java.util.UUID uuid = V6_GENERATOR.construct(rawTimestamp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt com.fasterxml.uuid.impl.TimeBasedEpochRandomGenerator knows the structure of trino timestamp tz values
| @Constraint(variable = "u", expression = "min(u, 6)") | ||
| public static Slice uuid_v6(@SqlType("timestamp(u) with time zone") long rawTimestamp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That results in a rather nasty exception
trino> select uuid_v6( current_timestamp(9) );
Query 20251128_140821_00027_837vf failed: variable 'u' is already set to 9 when trying to set 6
java.lang.IllegalStateException: variable 'u' is already set to 9 when trying to set 6
Engine is not supposed to throw anything other than TrinoExceptions.
| @Description("Generates a random UUID v6 from a given timestamp (RFC-9562)") | ||
| @ScalarFunction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provide explicit deterministic declaration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW this function looks deterministic. What's the use-case to have it?
| public static Slice uuid() | ||
| { | ||
| java.util.UUID uuid = randomUUID(); | ||
| java.util.UUID uuid = V4_GENERATOR.generate(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this better, different, or same as randomUUID the code used to use?
Description
Additional context and related issues
Release notes
(x) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
( ) Release notes are required, with the following suggested text: