[CALCITE-5898] Add UUID function (enabled in Presto library) - #5146
Draft
wasabii wants to merge 1 commit into
Draft
[CALCITE-5898] Add UUID function (enabled in Presto library)#5146wasabii wants to merge 1 commit into
wasabii wants to merge 1 commit into
Conversation
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Jira Link
CALCITE-5898
Changes Proposed
Adds two niladic functions to the
CALCITElibrary:UUIDV4()returns a random (version 4) UUID, as defined by RFC 4122.UUIDV7()returns a time-ordered (version 7) UUID, as defined by RFC 9562;values generated in sequence sort in creation order.
Both return
UUID(the type added in CALCITE-6738), and are non-deterministicand dynamic, so they are evaluated once per row.
UUIDV7()guarantees strict ordering even between values generated within thesame millisecond, using the Monotonic Random method of RFC 9562 section 6.2:
the 12-bit
rand_afield is seeded randomly at the start of each millisecondand then used as a counter. Ordering is maintained without locking, by packing
the timestamp and counter into a single
AtomicLongupdated with acompare-and-set loop. Random bits come from
SecureRandom, as recommended byRFC 9562 section 6.9.
When generating SQL for other dialects:
uuidv4()anduuidv7(); both pass throughunchanged.
UUIDV4()becomesNEWID().UUIDV4()becomesUUID().UUIDV7()has no SQL Server or Oracle equivalent, and is left untranslated.SQL Server's
uniqueidentifierdoes not sort by bit pattern, so a version 7value stored in that type is not returned in timestamp order.
Both functions are documented in
site/_docs/reference.md.UuidFunctionTestcovers the version and variant bits and monotonicity,
SqlOperatorTestcoversthe return types, and
RelToSqlConverterTestcovers the generated SQL for eachdialect.