Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions datafusion/ffi/src/tests/udf_udaf_udwf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ impl ScalarUDFImpl for PlacementUDF {
datafusion_common::internal_err!("placement_udf is not meant to be invoked")
}

fn is_strict(&self) -> bool {
true
}

fn placement(&self, args: &[ExpressionPlacement]) -> ExpressionPlacement {
// Push to the leaves only for a (Column, Literal) pairing, so the
// test catches dropped, reordered, or truncated arguments.
Expand Down
17 changes: 17 additions & 0 deletions datafusion/ffi/src/udf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ pub struct FFI_ScalarUDF {
udf: &Self,
config: FFI_ConfigOptions,
) -> FFI_Result<FFI_Option<FFI_ScalarUDF>>,

/// FFI equivalent to [`ScalarUDFImpl::is_strict`].
pub is_strict: unsafe extern "C" fn(udf: &Self) -> bool,
}

unsafe impl Send for FFI_ScalarUDF {}
Expand Down Expand Up @@ -193,6 +196,10 @@ unsafe extern "C" fn placement_fn_wrapper(
udf.inner().placement(&args).into()
}

unsafe extern "C" fn is_strict_fn_wrapper(udf: &FFI_ScalarUDF) -> bool {
udf.inner().is_strict()
}

unsafe extern "C" fn preserves_lex_ordering_fn_wrapper(
udf: &FFI_ScalarUDF,
inputs: SVec<FFI_ExprProperties>,
Expand Down Expand Up @@ -321,6 +328,7 @@ impl From<Arc<ScalarUDF>> for FFI_ScalarUDF {
library_marker_id: crate::get_library_marker_id,
preserves_lex_ordering: preserves_lex_ordering_fn_wrapper,
with_updated_config: with_updated_config_fn_wrapper,
is_strict: is_strict_fn_wrapper,
}
}
}
Expand Down Expand Up @@ -502,6 +510,10 @@ impl ScalarUDFImpl for ForeignScalarUDF {
self.udf.short_circuits
}

fn is_strict(&self) -> bool {
unsafe { (self.udf.is_strict)(&self.udf) }
}

fn coerce_types(&self, arg_types: &[DataType]) -> Result<Vec<DataType>> {
unsafe {
let arg_types = vec_datatype_to_rvec_wrapped(arg_types)?;
Expand Down Expand Up @@ -576,6 +588,10 @@ mod tests {
internal_err!("placement_udf is not meant to be invoked")
}

fn is_strict(&self) -> bool {
true
}

fn placement(&self, args: &[ExpressionPlacement]) -> ExpressionPlacement {
// Push to the leaves only for a (Column, Literal) pairing, so the
// test catches dropped, reordered, or truncated arguments.
Expand Down Expand Up @@ -663,6 +679,7 @@ mod tests {
ffi_udf.library_marker_id = crate::mock_foreign_marker_id;
let foreign_udf: Arc<dyn ScalarUDFImpl> = (&ffi_udf).into();
assert!(foreign_udf.is::<ForeignScalarUDF>());
assert!(foreign_udf.is_strict());

// Without the plumbing the override is dropped and every call is
// KeepInPlace. The three cases also check the arguments survive the
Expand Down
2 changes: 2 additions & 0 deletions datafusion/ffi/tests/ffi_udf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ mod tests {
let ffi_placement_func = (module.create_placement_udf)();
let foreign_func: Arc<dyn ScalarUDFImpl> = (&ffi_placement_func).into();

assert!(foreign_func.is_strict());

// The override pushes to the leaves only for (Column, Literal), so these
// also check the arguments cross the boundary in order.
assert_eq!(
Expand Down