diff --git a/datafusion/expr/src/type_coercion/functions.rs b/datafusion/expr/src/type_coercion/functions.rs index 5f52c7ccc20ef..2846603d7dc53 100644 --- a/datafusion/expr/src/type_coercion/functions.rs +++ b/datafusion/expr/src/type_coercion/functions.rs @@ -64,7 +64,12 @@ pub fn data_types_with_scalar_udf( return Ok(current_types.to_vec()); } - try_coerce_types(valid_types, current_types, &signature.type_signature) + try_coerce_types( + func.name(), + valid_types, + current_types, + &signature.type_signature, + ) } /// Performs type coercion for aggregate function arguments. @@ -100,7 +105,12 @@ pub fn data_types_with_aggregate_udf( return Ok(current_types.to_vec()); } - try_coerce_types(valid_types, current_types, &signature.type_signature) + try_coerce_types( + func.name(), + valid_types, + current_types, + &signature.type_signature, + ) } /// Performs type coercion for window function arguments. @@ -133,7 +143,12 @@ pub fn data_types_with_window_udf( return Ok(current_types.to_vec()); } - try_coerce_types(valid_types, current_types, &signature.type_signature) + try_coerce_types( + func.name(), + valid_types, + current_types, + &signature.type_signature, + ) } /// Performs type coercion for function arguments. @@ -144,6 +159,7 @@ pub fn data_types_with_window_udf( /// For more details on coercion in general, please see the /// [`type_coercion`](crate::type_coercion) module. pub fn data_types( + operation: impl AsRef, current_types: &[DataType], signature: &Signature, ) -> Result> { @@ -166,7 +182,12 @@ pub fn data_types( return Ok(current_types.to_vec()); } - try_coerce_types(valid_types, current_types, &signature.type_signature) + try_coerce_types( + operation, + valid_types, + current_types, + &signature.type_signature, + ) } fn is_well_supported_signature(type_signature: &TypeSignature) -> bool { @@ -187,6 +208,7 @@ fn is_well_supported_signature(type_signature: &TypeSignature) -> bool { } fn try_coerce_types( + operation: impl AsRef, valid_types: Vec>, current_types: &[DataType], type_signature: &TypeSignature, @@ -218,7 +240,8 @@ fn try_coerce_types( // none possible -> Error plan_err!( - "Coercion from {:?} to the signature {:?} failed.", + "{}: coercion from {:?} to the signature {:?} failed.", + operation.as_ref(), current_types, type_signature ) @@ -971,7 +994,7 @@ mod tests { Volatility::Stable, ); - let coerced_data_types = data_types(¤t_types, &signature).unwrap(); + let coerced_data_types = data_types("test", ¤t_types, &signature).unwrap(); assert_eq!(coerced_data_types, current_types); // make sure it can't coerce to a different size @@ -979,7 +1002,7 @@ mod tests { vec![DataType::FixedSizeList(Arc::clone(&inner), 3)], Volatility::Stable, ); - let coerced_data_types = data_types(¤t_types, &signature); + let coerced_data_types = data_types("test", ¤t_types, &signature); assert!(coerced_data_types.is_err()); // make sure it works with the same type. @@ -987,7 +1010,7 @@ mod tests { vec![DataType::FixedSizeList(Arc::clone(&inner), 2)], Volatility::Stable, ); - let coerced_data_types = data_types(¤t_types, &signature).unwrap(); + let coerced_data_types = data_types("test", ¤t_types, &signature).unwrap(); assert_eq!(coerced_data_types, current_types); Ok(()) diff --git a/datafusion/optimizer/src/analyzer/type_coercion.rs b/datafusion/optimizer/src/analyzer/type_coercion.rs index 58e390ee8bdba..669699b1fe4d2 100644 --- a/datafusion/optimizer/src/analyzer/type_coercion.rs +++ b/datafusion/optimizer/src/analyzer/type_coercion.rs @@ -1357,7 +1357,7 @@ mod test { let err = Projection::try_new(vec![udaf], empty).err().unwrap(); assert!( - err.strip_backtrace().starts_with("Error during planning: Error during planning: Coercion from [Utf8] to the signature Uniform(1, [Float64]) failed") + err.strip_backtrace().starts_with("Error during planning: Error during planning: MY_AVG: coercion from [Utf8] to the signature Uniform(1, [Float64]) failed") ); Ok(()) } @@ -1407,7 +1407,7 @@ mod test { .err() .unwrap() .strip_backtrace(); - assert!(err.starts_with("Error during planning: Error during planning: Coercion from [Utf8] to the signature Uniform(1, [Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Float32, Float64]) failed.")); + assert!(err.starts_with("Error during planning: Error during planning: avg: coercion from [Utf8] to the signature Uniform(1, [Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Float32, Float64]) failed.")); Ok(()) } diff --git a/datafusion/sqllogictest/test_files/aggregate.slt b/datafusion/sqllogictest/test_files/aggregate.slt index 917e037682f24..0b85eceef4550 100644 --- a/datafusion/sqllogictest/test_files/aggregate.slt +++ b/datafusion/sqllogictest/test_files/aggregate.slt @@ -76,26 +76,26 @@ statement error DataFusion error: Schema error: Schema contains duplicate unqual SELECT approx_distinct(c9) count_c9, approx_distinct(cast(c9 as varchar)) count_c9_str FROM aggregate_test_100 # csv_query_approx_percentile_cont_with_weight -statement error DataFusion error: Error during planning: Error during planning: Coercion from \[Utf8, Int8, Float64\] to the signature OneOf(.*) failed(.|\n)* +statement error DataFusion error: Error during planning: Error during planning: approx_percentile_cont_with_weight: coercion from \[Utf8, Int8, Float64\] to the signature OneOf(.*) failed(.|\n)* SELECT approx_percentile_cont_with_weight(c1, c2, 0.95) FROM aggregate_test_100 -statement error DataFusion error: Error during planning: Error during planning: Coercion from \[Int16, Utf8, Float64\] to the signature OneOf(.*) failed(.|\n)* +statement error DataFusion error: Error during planning: Error during planning: approx_percentile_cont_with_weight: coercion from \[Int16, Utf8, Float64\] to the signature OneOf(.*) failed(.|\n)* SELECT approx_percentile_cont_with_weight(c3, c1, 0.95) FROM aggregate_test_100 -statement error DataFusion error: Error during planning: Error during planning: Coercion from \[Int16, Int8, Utf8\] to the signature OneOf(.*) failed(.|\n)* +statement error DataFusion error: Error during planning: Error during planning: approx_percentile_cont_with_weight: coercion from \[Int16, Int8, Utf8\] to the signature OneOf(.*) failed(.|\n)* SELECT approx_percentile_cont_with_weight(c3, c2, c1) FROM aggregate_test_100 # csv_query_approx_percentile_cont_with_histogram_bins statement error DataFusion error: External error: This feature is not implemented: Tdigest max_size value for 'APPROX_PERCENTILE_CONT' must be UInt > 0 literal \(got data type Int64\)\. SELECT c1, approx_percentile_cont(c3, 0.95, -1000) AS c3_p95 FROM aggregate_test_100 GROUP BY 1 ORDER BY 1 -statement error DataFusion error: Error during planning: Error during planning: Coercion from \[Int16, Float64, Utf8\] to the signature OneOf(.*) failed(.|\n)* +statement error DataFusion error: Error during planning: Error during planning: approx_percentile_cont: coercion from \[Int16, Float64, Utf8\] to the signature OneOf(.*) failed(.|\n)* SELECT approx_percentile_cont(c3, 0.95, c1) FROM aggregate_test_100 -statement error DataFusion error: Error during planning: Error during planning: Coercion from \[Int16, Float64, Float64\] to the signature OneOf(.*) failed(.|\n)* +statement error DataFusion error: Error during planning: Error during planning: approx_percentile_cont: coercion from \[Int16, Float64, Float64\] to the signature OneOf(.*) failed(.|\n)* SELECT approx_percentile_cont(c3, 0.95, 111.1) FROM aggregate_test_100 -statement error DataFusion error: Error during planning: Error during planning: Coercion from \[Float64, Float64, Float64\] to the signature OneOf(.*) failed(.|\n)* +statement error DataFusion error: Error during planning: Error during planning: approx_percentile_cont: coercion from \[Float64, Float64, Float64\] to the signature OneOf(.*) failed(.|\n)* SELECT approx_percentile_cont(c12, 0.95, 111.1) FROM aggregate_test_100 statement error DataFusion error: This feature is not implemented: Percentile value for 'APPROX_PERCENTILE_CONT' must be a literal diff --git a/datafusion/sqllogictest/test_files/errors.slt b/datafusion/sqllogictest/test_files/errors.slt index b99bbf3dc0780..8a81a74b386f8 100644 --- a/datafusion/sqllogictest/test_files/errors.slt +++ b/datafusion/sqllogictest/test_files/errors.slt @@ -108,11 +108,11 @@ query error select avg(c1, c12) from aggregate_test_100; # AggregateFunction with wrong argument type -statement error Coercion +statement error DataFusion error: Error during planning: Error during planning: regr_slope: coercion from select regr_slope(1, '2'); # WindowFunction using AggregateFunction wrong signature -statement error Coercion +statement error DataFusion error: Error during planning: Error during planning: regr_slope: coercion from select c9, regr_slope(c11, '2') over () as min1 @@ -120,7 +120,7 @@ from aggregate_test_100 order by c9 # WindowFunction wrong signature -statement error DataFusion error: Error during planning: Error during planning: Coercion from \[Int32, Int64, Int64\] to the signature OneOf\(\[Any\(0\), Any\(1\), Any\(2\)\]\) failed +statement error DataFusion error: Error during planning: Error during planning: nth_value: coercion from \[Int32, Int64, Int64\] to the signature OneOf\(\[Any\(0\), Any\(1\), Any\(2\)\]\) failed select c9, nth_value(c5, 2, 3) over (order by c9) as nv1 diff --git a/datafusion/sqllogictest/test_files/expr.slt b/datafusion/sqllogictest/test_files/expr.slt index 499d279515c36..19a7d501a86e0 100644 --- a/datafusion/sqllogictest/test_files/expr.slt +++ b/datafusion/sqllogictest/test_files/expr.slt @@ -560,7 +560,7 @@ select repeat('-1.2', arrow_cast(3, 'Int32')); ---- -1.2-1.2-1.2 -query error DataFusion error: Error during planning: Error during planning: Coercion from \[Utf8, Float64\] to the signature +query error DataFusion error: Error during planning: Error during planning: repeat: coercion from \[Utf8, Float64\] to the signature select repeat('-1.2', 3.2); query T