myandpr commented on code in PR #21032:
URL: https://github.com/apache/datafusion/pull/21032#discussion_r2986597589


##########
datafusion/expr/src/type_coercion/functions.rs:
##########
@@ -1223,6 +1227,96 @@ mod tests {
         Ok(())
     }
 
+    #[test]
+    fn test_one_of_uses_generic_plan_error_instead_of_internal_error() {
+        let current_fields = vec![Arc::new(Field::new("t", DataType::Boolean, 
true))];
+        let signature = Signature::one_of(
+            vec![
+                TypeSignature::Coercible(vec![Coercion::new_exact(
+                    TypeSignatureClass::Decimal,
+                )]),
+                TypeSignature::Coercible(vec![Coercion::new_exact(
+                    TypeSignatureClass::Duration,
+                )]),
+            ],
+            Volatility::Immutable,
+        );
+
+        let err = fields_with_udf(&current_fields, 
&MockUdf(signature)).unwrap_err();
+        let err = err.to_string();
+
+        assert!(err.starts_with(
+            "Error during planning: Function 'test' failed to match any 
signature"
+        ));
+        assert!(!err.contains("Internal error"));
+        assert!(!err.contains("TypeSignatureClass"));
+    }
+
+    #[test]
+    fn test_one_of_uses_generic_plan_error_for_arity_mismatch() {
+        let current_fields = vec![Arc::new(Field::new("t", DataType::Int32, 
true))];
+        let signature = Signature::one_of(
+            vec![TypeSignature::Any(2), TypeSignature::Any(3)],
+            Volatility::Immutable,
+        );
+
+        let err = fields_with_udf(&current_fields, 
&MockUdf(signature)).unwrap_err();
+        let err = err.to_string();
+
+        assert!(err.starts_with(
+            "Error during planning: Function 'test' failed to match any 
signature"
+        ));
+        assert!(!err.contains("Internal error"));
+    }
+
+    struct AlwaysExecErrUdf(Signature);
+
+    impl UDFCoercionExt for AlwaysExecErrUdf {
+        fn name(&self) -> &str {
+            "test"
+        }
+
+        fn signature(&self) -> &Signature {
+            &self.0
+        }
+
+        fn coerce_types(&self, _arg_types: &[DataType]) -> 
Result<Vec<DataType>> {
+            exec_err!("boom")
+        }
+    }
+
+    #[test]
+    fn test_one_of_propagates_non_plan_errors() {
+        let current_fields = vec![Arc::new(Field::new("t", DataType::Int32, 
true))];
+        let signature =
+            Signature::one_of(vec![TypeSignature::UserDefined], 
Volatility::Immutable);
+
+        let err =
+            fields_with_udf(&current_fields, 
&AlwaysExecErrUdf(signature)).unwrap_err();
+

Review Comment:
   updated



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to