You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/05/10 13:08:53 UTC

[GitHub] [arrow-datafusion] Jimexist commented on a change in pull request #303: add random SQL function

Jimexist commented on a change in pull request #303:
URL: https://github.com/apache/arrow-datafusion/pull/303#discussion_r629343884



##########
File path: datafusion/src/physical_plan/math_expressions.rs
##########
@@ -116,3 +116,21 @@ math_unary_function!("exp", exp);
 math_unary_function!("ln", ln);
 math_unary_function!("log2", log2);
 math_unary_function!("log10", log10);
+
+/// random SQL function
+pub fn random(args: &[ColumnarValue]) -> Result<ColumnarValue> {
+    let len = match &args[0] {
+        ColumnarValue::Array(array) => array.len(),
+        _ => {
+            return Err(DataFusionError::Internal(
+                "Expect random function to take no param".to_string(),
+            ))
+        }
+    };
+    let mut rng = thread_rng();
+    let mut array = Vec::with_capacity(len);
+    for _ in 0..len {
+        array.push(Some(rng.gen_range(0.0..1.0)))

Review comment:
       not yet, i guess https://github.com/apache/arrow-rs/pull/275 is needed first?




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

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