shruti2522 commented on code in PR #17100:
URL: https://github.com/apache/datafusion/pull/17100#discussion_r2267718179


##########
datafusion/spark/src/function/utils.rs:
##########
@@ -65,43 +65,56 @@ pub mod test {
 
             match expected {
                 Ok(expected) => {
-                    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,
-                        arg_fields: arg_fields.clone(),
-                        config_options: $CONFIG_OPTIONS,
-                    });
-                    assert_eq!(result.is_ok(), true, "function returned an 
error: {}", result.unwrap_err());
+                    if let Ok(return_field) = return_field {
+                        assert_eq!(return_field.data_type(), 
&$EXPECTED_DATA_TYPE);
 
-                    let result = 
result.unwrap().to_array(cardinality).expect("Failed to convert to array");
-                    let result = 
result.as_any().downcast_ref::<$ARRAY_TYPE>().expect("Failed to convert to 
type");
-                    assert_eq!(result.data_type(), &$EXPECTED_DATA_TYPE);
+                        match 
func.invoke_with_args(datafusion_expr::ScalarFunctionArgs{
+                            args: $ARGS,
+                            number_rows: cardinality,
+                            return_field,
+                            arg_fields: arg_fields.clone(),
+                            config_options: $CONFIG_OPTIONS,
+                        }) {
+                            Ok(col_value) => {
+                                match col_value.to_array(cardinality) {
+                                    Ok(array) => {
+                                        let result = array
+                                            .as_any()
+                                            .downcast_ref::<$ARRAY_TYPE>()
+                                            .expect("Failed to convert to 
type");
+                                        assert_eq!(result.data_type(), 
&$EXPECTED_DATA_TYPE);
 
-                    // value is correct
-                    match expected {
-                        Some(v) => assert_eq!(result.value(0), v),
-                        None => assert!(result.is_null(0)),
-                    };
-                }
-                Err(expected_error) => {
-                    if return_field.is_err() {
-                        match return_field {
-                            Ok(_) => assert!(false, "expected error"),
-                            Err(error) => { 
datafusion_common::assert_contains!(expected_error.strip_backtrace(), 
error.strip_backtrace()); }
+                                       // value is correct
+                                        match expected {
+                                            Some(v) => 
assert_eq!(result.value(0), v),
+                                            None => assert!(result.is_null(0)),
+                                        };
+                                    }
+                                    Err(err) => {
+                                        panic!("Failed to convert to array: 
{err}");
+                                    }
+                                }
+                            }
+                            Err(err) => {
+                                panic!("function returned an error: {err}");
+                            }
                         }
+                    } else {
+                        panic!("Expected return_field to be Ok but got Err");
                     }
-                    else {
-                        let return_field = return_field.unwrap();
-
+                }
+                Err(expected_error) => {
+                    if let Err(error) = &return_field {

Review Comment:
   simplified `return_field.is_err() + unwrap()` to `if let Err(error) = 
&return_field {`
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to