martin-g commented on code in PR #21032:
URL: https://github.com/apache/datafusion/pull/21032#discussion_r2984123499
##########
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(¤t_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(¤t_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(¤t_fields,
&AlwaysExecErrUdf(signature)).unwrap_err();
+
Review Comment:
Here you can assert that `err` is `DataFusionError::Exec`
##########
datafusion/sqllogictest/test_files/spark/math/hex.slt:
##########
@@ -56,7 +56,7 @@ SELECT hex(column1) FROM VALUES (arrow_cast('hello',
'LargeBinary')), (NULL), (a
NULL
776F726C64
-statement error Function 'hex' expects 1 arguments but received 2
+statement error DataFusion error: Error during planning: Function 'hex' failed
to match any signature
Review Comment:
IMO the previous error was more actionable by the user.
Now the user will need to consult with the documentation of `hex` and
compare it against the way (s)he tries to use it.
##########
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(¤t_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(¤t_fields,
&MockUdf(signature)).unwrap_err();
+ let err = err.to_string();
Review Comment:
Same here.
##########
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(¤t_fields,
&MockUdf(signature)).unwrap_err();
+ let err = err.to_string();
Review Comment:
You can assert that the Err type is DataFusionError::Plan before calling
`.to_string()` on it.
--
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]