This is an automated email from the ASF dual-hosted git repository.

sarutak pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark-connect-rust.git


The following commit(s) were added to refs/heads/master by this push:
     new a0b68c4  [SPARK-53363] Add uuid builtin function
a0b68c4 is described below

commit a0b68c4a2f8a992d71e076bb40f0678a18081ef7
Author: Kousuke Saruta <[email protected]>
AuthorDate: Fri Oct 3 16:22:31 2025 +0900

    [SPARK-53363] Add uuid builtin function
    
    ### What changes were proposed in this pull request?
    This PR proposes to add `uuid` builtin function.
    
    ### Why are the changes needed?
    This function is supported as of Spark 3.5.0 but spark-connect-rust doesn't 
have.
    
    ### Does this PR introduce _any_ user-facing change?
    Yes, but doesn't break compatibility because this PR just add a new builtin 
function.
    
    ### How was this patch tested?
    Add new test.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    No.
    
    Closes #7 from sarutak/uuid-builtin-function.
    
    Authored-by: Kousuke Saruta <[email protected]>
    Signed-off-by: Kousuke Saruta <[email protected]>
---
 crates/connect/src/functions/mod.rs | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/crates/connect/src/functions/mod.rs 
b/crates/connect/src/functions/mod.rs
index 89892ba..b518b4d 100644
--- a/crates/connect/src/functions/mod.rs
+++ b/crates/connect/src/functions/mod.rs
@@ -166,6 +166,8 @@ pub fn expr(val: &str) -> Column {
     })
 }
 
+gen_func!(uuid, [], "Returns an universally unique identifier (UUID) string. 
The value is returned as a canonical UUID 36-character string.");
+
 // Math Functions
 
 gen_func!(sqrt, [col: Column], "Computes the square root of the specified 
float value.");
@@ -1668,11 +1670,13 @@ mod tests {
     use super::*;
 
     use core::f64;
+    use regex::Regex;
     use std::sync::Arc;
 
     use arrow::{
         array::{
-            ArrayRef, BooleanArray, Float64Array, Int32Array, Int64Array, 
StringArray, StructArray,
+            Array, ArrayRef, BooleanArray, Float64Array, Int32Array, 
Int64Array, StringArray,
+            StructArray,
         },
         datatypes::{DataType, Field, Schema},
         record_batch::RecordBatch,
@@ -1915,6 +1919,24 @@ mod tests {
         false
     );
 
+    #[tokio::test]
+    async fn test_func_uuid() -> Result<(), SparkError> {
+        let spark = setup().await;
+
+        let df = spark.range(Some(1), 2, 1, Some(1));
+        let res = df.select([uuid().alias("uuid")]).collect().await?;
+        let res_column = res.column_by_name("uuid").unwrap();
+        let res_column = 
res_column.as_any().downcast_ref::<StringArray>().unwrap();
+        assert_eq!(res_column.len(), 1);
+
+        let uuid = res_column.value(0);
+        let expect_pattern =
+            
Regex::new("^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$").unwrap();
+        assert!(expect_pattern.is_match(uuid));
+
+        Ok(())
+    }
+
     // math functions
     test_func!(
         test_func_sqrt,


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to