Skip to content
Merged
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
18 changes: 15 additions & 3 deletions datafusion/spark/src/function/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub mod test {
let expected: datafusion_common::Result<Option<$EXPECTED_TYPE>> = $EXPECTED;
let func = $FUNC;

let arg_fields_owned = $ARGS
let arg_fields_owned: Vec<arrow::datatypes::Field> = $ARGS
Copy link
Preview

Copilot AI May 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] If $ARGS already yields a Vecarrow::datatypes::Field, the explicit type annotation might be redundant. Consider removing it or adding a comment to clarify its purpose.

Suggested change
let arg_fields_owned: Vec<arrow::datatypes::Field> = $ARGS
let arg_fields_owned = $ARGS

Copilot uses AI. Check for mistakes.

.iter()
.enumerate()
.map(|(idx, arg)| {
Expand All @@ -42,6 +42,8 @@ pub mod test {
})
.collect::<Vec<_>>();

let arg_fields: Vec<&arrow::datatypes::Field> = arg_fields_owned.iter().collect();

let cardinality = $ARGS
.iter()
.fold(Option::<usize>::None, |acc, arg| match arg {
Expand All @@ -67,7 +69,12 @@ pub mod test {
let return_field = return_field.unwrap();
assert_eq!(return_field.data_type(), &$EXPECTED_DATA_TYPE);

let result = func.invoke_with_args(datafusion_expr::ScalarFunctionArgs{args: $ARGS, number_rows: cardinality, return_field: &return_field, arg_fields: arg_fields_owned.iter().collect()});
let result = func.invoke_with_args(datafusion_expr::ScalarFunctionArgs{
args: $ARGS,
number_rows: cardinality,
return_field: &return_field,
arg_fields: arg_fields.clone(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in particular the change is to avoid calling collect twice and instead create the vec once and reuse it

});
assert_eq!(result.is_ok(), true, "function returned an error: {}", result.unwrap_err());

let result = result.unwrap().to_array(cardinality).expect("Failed to convert to array");
Expand All @@ -91,7 +98,12 @@ pub mod test {
let return_field = return_field.unwrap();

// invoke is expected error - cannot use .expect_err() due to Debug not being implemented
match func.invoke_with_args(datafusion_expr::ScalarFunctionArgs{args: $ARGS, number_rows: cardinality, return_field: &return_field, arg_fields: arg_fields_owned.iter().collect()}) {
match func.invoke_with_args(datafusion_expr::ScalarFunctionArgs{
args: $ARGS,
number_rows: cardinality,
return_field: &return_field,
arg_fields,
}) {
Ok(_) => assert!(false, "expected error"),
Err(error) => {
assert!(expected_error.strip_backtrace().starts_with(&error.strip_backtrace()));
Expand Down