findepi opened a new pull request, #14668: URL: https://github.com/apache/datafusion/pull/14668
This is currently a preview PR for https://github.com/apache/datafusion/issues/12635 to share status of the work. Based on `add_one` function, this creates `add_one_udf` (by convention, configurable): ```rust #[excalibur_function] fn add_one(a: u64) -> u64 { a + 1 } ``` The generated `ScalarUDFImpl` is fully functional, with signature derived from the Rust-level signature of the decorated function: ```rust #[test] fn simple_function_signature() { let udf = add_one_udf(); assert_eq!(udf.name(), "add_one"); assert_eq!( udf.signature(), &Signature::coercible( vec![TypeSignatureClass::Native(Arc::new(NativeType::UInt64))], Volatility::Immutable ) ); let return_type = udf.return_type(&[DataType::UInt64]).unwrap(); assert_eq!(return_type, DataType::UInt64); } #[test] fn simple_function_invoke_array() { let udf = add_one_udf(); let invoke_args = vec![ColumnarValue::Array(Arc::new(UInt64Array::from(vec![ 1000, 2000, 3000, 4000, 5000, ])))]; let ColumnarValue::Array(result_array) = udf .invoke_with_args(ScalarFunctionArgs { args: invoke_args, number_rows: 5, return_type: &DataType::UInt64, }) .unwrap() else { panic!("Expected array result"); }; assert_eq!( &*result_array, &UInt64Array::from(vec![1001, 2001, 3001, 4001, 5001]) ); } #[test] fn simple_function_invoke_scalar() { let udf = add_one_udf(); let invoke_args = vec![ColumnarValue::Scalar(ScalarValue::UInt64(Some(1000)))]; let ColumnarValue::Array(result_array) = udf .invoke_with_args(ScalarFunctionArgs { args: invoke_args, number_rows: 1, return_type: &DataType::UInt64, }) .unwrap() else { panic!("Expected array result"); }; assert_eq!(&*result_array, &UInt64Array::from(vec![1001])); } ``` -- 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