Apache DataFusion SQL Query Engine
Report current operation when coercion fails (#13628)
Piotr Findeisen55e56c47a61e
diff --git a/datafusion/expr/src/type_coercion/functions.rs b/datafusion/expr/src/type_coercion/functions.rsindex 3dbffce3c9..9d15d96939 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(+ function_name: impl AsRef<str>,current_types: &[DataType],signature: &Signature,) -> Result<Vec<DataType>> {@@ -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(+ function_name,+ 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(+ function_name: impl AsRef<str>,valid_types: Vec<Vec<DataType>>,current_types: &[DataType],type_signature: &TypeSignature,@@ -218,7 +240,8 @@ fn try_coerce_types(// none possible -> Errorplan_err!(- "Coercion from {:?} to the signature {:?} failed.",+ "Failed to coerce arguments to satisfy a call to {} function: coercion from {:?} to the signature {:?} failed.",+ function_name.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.rsindex 71abfda5fc..628c1498f9 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: Failed to coerce arguments to satisfy a call to MY_AVG function: 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: Failed to coerce arguments to satisfy a call to avg function: 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.sltindex 917e037682..e76c1466a5 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 unqualSELECT 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: Failed to coerce arguments to satisfy a call to approx_percentile_cont_with_weight function: 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: Failed to coerce arguments to satisfy a call to approx_percentile_cont_with_weight function: 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: Failed to coerce arguments to satisfy a call to approx_percentile_cont_with_weight function: 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_binsstatement 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: Failed to coerce arguments to satisfy a call to approx_percentile_cont function: 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: Failed to coerce arguments to satisfy a call to approx_percentile_cont function: 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: Failed to coerce arguments to satisfy a call to approx_percentile_cont function: coercion from \[Float64, Float64, Float64\] to the signature OneOf(.*) failed(.|\n)*SELECT approx_percentile_cont(c12, 0.95, 111.1) FROM aggregate_test_100statement error DataFusion error: This feature is not implemented: Percentile value for 'APPROX_PERCENTILE_CONT' must be a literaldiff --git a/datafusion/sqllogictest/test_files/errors.slt b/datafusion/sqllogictest/test_files/errors.sltindex b99bbf3dc0..14d5678e50 100644--- a/datafusion/sqllogictest/test_files/errors.slt+++ b/datafusion/sqllogictest/test_files/errors.slt@@ -108,11 +108,11 @@ query errorselect 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: Failed to coerce arguments to satisfy a call to regr_slope function: coercion fromselect regr_slope(1, '2');# WindowFunction using AggregateFunction wrong signature-statement error Coercion+statement error DataFusion error: Error during planning: Error during planning: Failed to coerce arguments to satisfy a call to regr_slope function: coercion fromselectc9,regr_slope(c11, '2') over () as min1@@ -120,7 +120,7 @@ from aggregate_test_100order 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: Failed to coerce arguments to satisfy a call to nth_value function: coercion from \[Int32, Int64, Int64\] to the signature OneOf\(\[Any\(0\), Any\(1\), Any\(2\)\]\) failedselectc9,nth_value(c5, 2, 3) over (order by c9) as nv1diff --git a/datafusion/sqllogictest/test_files/expr.slt b/datafusion/sqllogictest/test_files/expr.sltindex 499d279515..9b8dfc2186 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: Failed to coerce arguments to satisfy a call to repeat function: coercion from \[Utf8, Float64\] to the signatureselect repeat('-1.2', 3.2);query T