MCPcopy Create free account
hub / github.com/apache/datafusion / invoke_and_assert

Function invoke_and_assert

datafusion/functions-nested/src/array_has.rs:1209–1234  ·  view source on GitHub ↗

Invoke a two-argument list UDF with the given arrays and assert the boolean output matches `expected`.

(
        udf: &dyn ScalarUDFImpl,
        haystack: &ArrayRef,
        needle: ArrayRef,
        expected: &[Option<bool>],
    )

Source from the content-addressed store, hash-verified

1207 /// Invoke a two-argument list UDF with the given arrays and assert the
1208 /// boolean output matches `expected`.
1209 fn invoke_and_assert(
1210 udf: &dyn ScalarUDFImpl,
1211 haystack: &ArrayRef,
1212 needle: ArrayRef,
1213 expected: &[Option<bool>],
1214 ) {
1215 let num_rows = haystack.len();
1216 let list_type = haystack.data_type();
1217 let result = udf
1218 .invoke_with_args(ScalarFunctionArgs {
1219 args: vec![
1220 ColumnarValue::Array(Arc::clone(haystack)),
1221 ColumnarValue::Array(needle),
1222 ],
1223 arg_fields: vec![
1224 Arc::new(Field::new("haystack", list_type.clone(), false)),
1225 Arc::new(Field::new("needle", list_type.clone(), false)),
1226 ],
1227 number_rows: num_rows,
1228 return_field: Arc::new(Field::new("return", DataType::Boolean, true)),
1229 config_options: Arc::new(ConfigOptions::default()),
1230 })
1231 .unwrap();
1232 let output = result.into_array(num_rows).unwrap();
1233 assert_eq!(output.as_boolean().iter().collect::<Vec<_>>(), expected);
1234 }
1235
1236 #[test]
1237 fn test_sliced_list_offsets() {

Callers 2

test_sliced_list_offsetsFunction · 0.85

Calls 5

newFunction · 0.85
lenMethod · 0.45
data_typeMethod · 0.45
invoke_with_argsMethod · 0.45
into_arrayMethod · 0.45

Tested by 2

test_sliced_list_offsetsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…