alamb commented on code in PR #14675:
URL: https://github.com/apache/datafusion/pull/14675#discussion_r1957094423


##########
datafusion/sqllogictest/test_files/functions.slt:
##########
@@ -720,6 +720,14 @@ select count(distinct u) from uuid_table;
 ----
 2
 
+# must be valid uuidv4 format
+query B
+SELECT REGEXP_LIKE(uuid(),

Review Comment:
   👍 



##########
datafusion/functions/src/string/uuid.rs:
##########
@@ -87,9 +88,25 @@ impl ScalarUDFImpl for UuidFunc {
         if !args.is_empty() {
             return internal_err!("{} function does not accept arguments", 
self.name());
         }
-        let values = std::iter::repeat_with(|| 
Uuid::new_v4().to_string()).take(num_rows);
-        let array = GenericStringArray::<i32>::from_iter_values(values);
-        Ok(ColumnarValue::Array(Arc::new(array)))
+
+        // Generate random u128 values
+        let mut rng = rand::thread_rng();
+        let mut randoms = vec![0u128; num_rows];
+        rng.fill(&mut randoms[..]);
+
+        let mut builder =
+            GenericStringBuilder::<i32>::with_capacity(num_rows, num_rows * 
36);
+
+        let mut buffer = [0u8; 36];
+        for x in &mut randoms {
+            // From Uuid::new_v4(): Mask out the version and variant bits

Review Comment:
   I double checked this is the case: 
   https://docs.rs/uuid/latest/src/uuid/v4.rs.html#33-39



##########
datafusion/functions/src/string/uuid.rs:
##########
@@ -87,9 +88,25 @@ impl ScalarUDFImpl for UuidFunc {
         if !args.is_empty() {
             return internal_err!("{} function does not accept arguments", 
self.name());
         }
-        let values = std::iter::repeat_with(|| 
Uuid::new_v4().to_string()).take(num_rows);

Review Comment:
   This old code will allocate a new string, create uuid, then copy that string 
into the output. 
   
   Removing that allocation alone is likely to make a big difference



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to