alamb commented on code in PR #10193: URL: https://github.com/apache/datafusion/pull/10193#discussion_r1576665520
########## datafusion/core/tests/user_defined/user_defined_scalar_functions.rs: ########## @@ -403,123 +398,6 @@ async fn test_user_defined_functions_with_alias() -> Result<()> { Ok(()) } -#[derive(Debug)] -pub struct RandomUDF { - signature: Signature, -} - -impl RandomUDF { - pub fn new() -> Self { - Self { - signature: Signature::any(0, Volatility::Volatile), - } - } -} - -impl ScalarUDFImpl for RandomUDF { - fn as_any(&self) -> &dyn std::any::Any { - self - } - - fn name(&self) -> &str { - "random_udf" - } - - fn signature(&self) -> &Signature { - &self.signature - } - - fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> { - Ok(Float64) - } - - fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue> { - let len: usize = match &args[0] { - // This udf is always invoked with zero argument so its argument - // is a null array indicating the batch size. - ColumnarValue::Array(array) if array.data_type().is_null() => array.len(), - _ => { - return Err(datafusion::error::DataFusionError::Internal( - "Invalid argument type".to_string(), - )) - } - }; - let mut rng = thread_rng(); - let values = iter::repeat_with(|| rng.gen_range(0.1..1.0)).take(len); - let array = Float64Array::from_iter_values(values); - Ok(ColumnarValue::Array(Arc::new(array))) - } -} - -/// Ensure that a user defined function with zero argument will be invoked -/// with a null array indicating the batch size. -#[tokio::test] -async fn test_user_defined_functions_zero_argument() -> Result<()> { - let ctx = SessionContext::new(); - - let schema = Arc::new(Schema::new(vec![Field::new( - "index", - DataType::UInt8, - false, - )])); - - let batch = RecordBatch::try_new( - schema, - vec![Arc::new(UInt8Array::from_iter_values([1, 2, 3]))], - )?; - - ctx.register_batch("data_table", batch)?; - - let random_normal_udf = ScalarUDF::from(RandomUDF::new()); - ctx.register_udf(random_normal_udf); - - let result = plan_and_collect( - &ctx, - "SELECT random_udf() AS random_udf, random() AS native_random FROM data_table", - ) - .await?; - - assert_eq!(result.len(), 1); - let batch = &result[0]; - let random_udf = batch - .column(0) - .as_any() - .downcast_ref::<Float64Array>() - .unwrap(); - let native_random = batch - .column(1) - .as_any() - .downcast_ref::<Float64Array>() - .unwrap(); - - assert_eq!(random_udf.len(), native_random.len()); - - let mut previous = -1.0; - for i in 0..random_udf.len() { - assert!(random_udf.value(i) >= 0.0 && random_udf.value(i) < 1.0); - assert!(random_udf.value(i) != previous); - previous = random_udf.value(i); - } - - Ok(()) -} - -#[tokio::test] -async fn deregister_udf() -> Result<()> { Review Comment: This function is just moved , the test remains -- 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