use std::sync::Arc;
use arrow_array::{Int32Array, RecordBatch};
use arrow_schema::{DataType, Field, Schema};
use arrow_udf::function;
#[function("gcd(int, int) -> int", output = "gcd_batch")]
fn gcd(mut a: i32, mut b: i32) -> i32 {
while b != 0 {
(a, b) = (b, a % b);
}
a
}
fn main() {
let schema = Schema::new(vec![
Field::new("x", DataType::Int32, true),
Field::new("y", DataType::Int32, true),
]);
let arg0 = Int32Array::from(vec![Some(25), None]);
let arg1 = Int32Array::from(vec![Some(15), None]);
let input =
RecordBatch::try_new(Arc::new(schema), vec![Arc::new(arg0), Arc::new(arg1)]).unwrap();
#[cfg(not(feature = "global_registry"))]
let output = gcd_batch(&input).unwrap();
#[cfg(feature = "global_registry")]
let output = {
let int32 = Field::new("", DataType::Int32, true);
let sig = arrow_udf::sig::REGISTRY
.get("gcd", &[int32.clone(), int32.clone()], &int32)
.expect("gcd function");
sig.function.as_scalar().unwrap()(&input).unwrap()
};
arrow_cast::pretty::print_batches(std::slice::from_ref(&input)).unwrap();
arrow_cast::pretty::print_batches(std::slice::from_ref(&output)).unwrap();
}