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


##########
datafusion/functions/src/string/uuid.rs:
##########
@@ -87,7 +88,13 @@ 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);
+
+        // Generate random u128 values
+        let mut rng = rand::thread_rng();
+        let mut randoms = vec![0u128; num_rows];
+        rng.fill(&mut randoms[..]);
+
+        let values = randoms.into_iter().map(|x| 
Uuid::from_u128(x).to_string());

Review Comment:
   Thanks @simonvandel 
   I'm just curious how this is faster as under the hood it uses the same 
approach
   ```
       pub fn new_v4() -> Uuid {
           // This is an optimized method for generating random UUIDs that just 
masks
           // out the bits for the version and variant and sets them both 
together
           Uuid::from_u128(
               crate::rng::u128() & 0xFFFFFFFFFFFF4FFFBFFFFFFFFFFFFFFF | 
0x40008000000000000000,
           )
       }
   ```
   
   probably `repeat_with().take()` is slow



-- 
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