joroKr21 commented on code in PR #12922:
URL: https://github.com/apache/datafusion/pull/12922#discussion_r1801484804


##########
datafusion/functions/src/macros.rs:
##########
@@ -226,9 +226,8 @@ macro_rules! make_math_unary_udf {
                     $EVALUATE_BOUNDS(inputs)
                 }
 
-                fn invoke(&self, args: &[ColumnarValue]) -> 
Result<ColumnarValue> {
-                    let args = ColumnarValue::values_to_arrays(args)?;
-
+                fn invoke(&self, col_args: &[ColumnarValue]) -> 
Result<ColumnarValue> {

Review Comment:
   Well simply the issue is that I don't know what is the batch size expected 
to return from this function. Usually it's inferred by any of the argument's 
length. But if all arguments are scalar values, then I can return a scalar 
value and all is well. This works for immutable functions but not for volatile 
ones. See e.g.
   
   ```rust
   impl ScalarUDFImpl for RandomFunc {
       fn as_any(&self) -> &dyn Any {
           self
       }
   
       fn name(&self) -> &str {
           "random"
       }
   
       fn signature(&self) -> &Signature {
           &self.signature
       }
   
       fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
           Ok(Float64)
       }
   
       fn invoke(&self, _args: &[ColumnarValue]) -> Result<ColumnarValue> {
           not_impl_err!("{} function does not accept arguments", self.name())
       }
   
       fn invoke_no_args(&self, num_rows: usize) -> Result<ColumnarValue> {
           let mut rng = thread_rng();
           let mut values = vec![0.0; num_rows];
           // Equivalent to set each element with rng.gen_range(0.0..1.0), but 
more efficient
           rng.fill(&mut values[..]);
           let array = Float64Array::from(values);
   
           Ok(ColumnarValue::Array(Arc::new(array)))
       }
   }
   ```
   
   What if I wanted to implement `RandomFunc` with an upper bound? I can't use 
`invoke_no_args` because I have one argument and I can't use `invoke` because 
it doesn't tell me how many rows I should produce.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to