liukun4515 commented on code in PR #10193:
URL: https://github.com/apache/datafusion/pull/10193#discussion_r1580661398


##########
datafusion/functions/src/math/random.rs:
##########
@@ -64,45 +61,9 @@ impl ScalarUDFImpl for RandomFunc {
         Ok(Float64)
     }
 
-    fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue> {
-        random(args)
-    }
-}
-
-/// Random SQL function
-fn random(args: &[ColumnarValue]) -> Result<ColumnarValue> {
-    let len: usize = match &args[0] {
-        ColumnarValue::Array(array) => array.len(),
-        _ => return exec_err!("Expect random function to take no param"),
-    };
-    let mut rng = thread_rng();
-    let values = iter::repeat_with(|| rng.gen_range(0.0..1.0)).take(len);
-    let array = Float64Array::from_iter_values(values);
-    Ok(ColumnarValue::Array(Arc::new(array)))
-}
-
-#[cfg(test)]
-mod test {
-    use std::sync::Arc;
-
-    use arrow::array::NullArray;
-
-    use datafusion_common::cast::as_float64_array;
-    use datafusion_expr::ColumnarValue;
-
-    use crate::math::random::random;
-
-    #[test]
-    fn test_random_expression() {
-        let args = vec![ColumnarValue::Array(Arc::new(NullArray::new(1)))];
-        let array = random(&args)
-            .expect("failed to initialize function random")
-            .into_array(1)
-            .expect("Failed to convert to array");
-        let floats =
-            as_float64_array(&array).expect("failed to initialize function 
random");
-
-        assert_eq!(floats.len(), 1);
-        assert!(0.0 <= floats.value(0) && floats.value(0) < 1.0);
+    fn invoke(&self, _args: &[ColumnarValue]) -> Result<ColumnarValue> {

Review Comment:
   > We have test like
   > 
   > ```
   > query II
   > SELECT octet_length(uuid()), length(uuid())
   > ----
   > 36 36
   > ```
   
   I means the `uuid` function is also `invoked once per row rather than once 
per batch` like `random()` function mentioned by alamb.
   
   I test the function in the spark
   
   ```
   spark-sql> desc test;
   col1    int     NULL
   Time taken: 0.065 seconds, Fetched 1 row(s)
   
   
   spark-sql> select * from test;
   1
   2
   
   
   
   spark-sql> select *,uuid() from test;
   1       6b04b66c-2e6c-4925-8b18-a9d51d5ed80a
   2       3e0be0c2-9ff2-422a-8f3f-5cdb6551264b
   ```



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