Skip to content

Commit

Permalink
Properly return a scalar value from a UDF when only input is scalar (#…
Browse files Browse the repository at this point in the history
…753)

Fixes #699
  • Loading branch information
mwylde authored Oct 10, 2024
1 parent 655d388 commit 1d95e13
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion crates/arroyo-udf/arroyo-udf-host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ impl ScalarUDFImpl for SyncUdfDylib {
.max()
.unwrap();

let all_scalars = args.iter().all(|c| matches!(c, ColumnarValue::Scalar(_)));

let args = args
.iter()
.map(|arg| arg.clone().into_array(num_rows).unwrap().to_data())
Expand All @@ -402,7 +404,15 @@ impl ScalarUDFImpl for SyncUdfDylib {
match result {
RunResult::Ok(FfiArraySchema(array, schema)) => {
let result_array = unsafe { from_ffi(array, &schema).unwrap() };
Ok(ColumnarValue::Array(make_array(result_array)))

let array = make_array(result_array);
if all_scalars {
Ok(ColumnarValue::Scalar(ScalarValue::try_from_array(
&array, 0,
)?))
} else {
Ok(ColumnarValue::Array(array))
}
}
RunResult::Err => {
panic!("panic in UDF {}", self.name);
Expand Down

0 comments on commit 1d95e13

Please sign in to comment.