wasabii opened a new pull request, #5146:
URL: https://github.com/apache/calcite/pull/5146

   ## Jira Link
   
   [CALCITE-5898](https://issues.apache.org/jira/browse/CALCITE-5898)
   
   ## Changes Proposed
   
   Adds two niladic functions to the `CALCITE` library:
   
   * `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-deterministic
   and dynamic, so they are evaluated once per row.
   
   `UUIDV7()` guarantees strict ordering even between values generated within 
the
   same millisecond, using the Monotonic Random method of RFC 9562 section 6.2:
   the 12-bit `rand_a` field is seeded randomly at the start of each millisecond
   and then used as a counter. Ordering is maintained without locking, by 
packing
   the timestamp and counter into a single `AtomicLong` updated with a
   compare-and-set loop. Random bits come from `SecureRandom`, as recommended by
   RFC 9562 section 6.9.
   
   When generating SQL for other dialects:
   
   * PostgreSQL 17+ has native `uuidv4()` and `uuidv7()`; both pass through
     unchanged.
   * SQL Server: `UUIDV4()` becomes `NEWID()`.
   * Oracle 23ai+: `UUIDV4()` becomes `UUID()`.
   * `UUIDV7()` has no SQL Server or Oracle equivalent, and is left 
untranslated.
     SQL Server's `uniqueidentifier` does not sort by bit pattern, so a version 
7
     value stored in that type is not returned in timestamp order.
   
   Both functions are documented in `site/_docs/reference.md`. 
`UuidFunctionTest`
   covers the version and variant bits and monotonicity, `SqlOperatorTest` 
covers
   the return types, and `RelToSqlConverterTest` covers the generated SQL for 
each
   dialect.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to