From b8b47a23d2e6ddf1ae5cb6abe1d3c66ba50bf526 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Thu, 21 Oct 2021 10:47:12 -0400 Subject: [PATCH 1/2] Improve error messages when operations are not supported --- .../src/physical_plan/expressions/binary.rs | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/datafusion/src/physical_plan/expressions/binary.rs b/datafusion/src/physical_plan/expressions/binary.rs index 4a3ef581e6f3b..456e8d42a5df3 100644 --- a/datafusion/src/physical_plan/expressions/binary.rs +++ b/datafusion/src/physical_plan/expressions/binary.rs @@ -118,7 +118,8 @@ macro_rules! compute_utf8_op_scalar { )?)) } else { Err(DataFusionError::Internal(format!( - "compute_utf8_op_scalar failed to cast literal value {}", + "compute_utf8_op_scalar for '{}' failed to cast literal value {}", + stringify!($OP), $RIGHT ))) } @@ -171,8 +172,8 @@ macro_rules! binary_string_array_op_scalar { let result: Result> = match $LEFT.data_type() { DataType::Utf8 => compute_utf8_op_scalar!($LEFT, $RIGHT, $OP, StringArray), other => Err(DataFusionError::Internal(format!( - "Data type {:?} not supported for scalar operation on string array", - other + "Data type {:?} not supported for scalar operation '{}' on string array", + other, stringify!($OP) ))), }; Some(result) @@ -184,8 +185,8 @@ macro_rules! binary_string_array_op { match $LEFT.data_type() { DataType::Utf8 => compute_utf8_op!($LEFT, $RIGHT, $OP, StringArray), other => Err(DataFusionError::Internal(format!( - "Data type {:?} not supported for binary operation on string arrays", - other + "Data type {:?} not supported for binary operation '{}' on string arrays", + other, stringify!($OP) ))), } }}; @@ -208,8 +209,8 @@ macro_rules! binary_primitive_array_op { DataType::Float32 => compute_op!($LEFT, $RIGHT, $OP, Float32Array), DataType::Float64 => compute_op!($LEFT, $RIGHT, $OP, Float64Array), other => Err(DataFusionError::Internal(format!( - "Data type {:?} not supported for binary operation on primitive arrays", - other + "Data type {:?} not supported for binary operation '{}' on primitive arrays", + other, stringify!($OP) ))), } }}; @@ -232,8 +233,8 @@ macro_rules! binary_primitive_array_op_scalar { DataType::Float32 => compute_op_scalar!($LEFT, $RIGHT, $OP, Float32Array), DataType::Float64 => compute_op_scalar!($LEFT, $RIGHT, $OP, Float64Array), other => Err(DataFusionError::Internal(format!( - "Data type {:?} not supported for scalar operation on primitive array", - other + "Data type {:?} not supported for scalar operation '{}' on primitive array", + other, stringify!($OP) ))), }; Some(result) @@ -276,8 +277,8 @@ macro_rules! binary_array_op_scalar { compute_op_scalar!($LEFT, $RIGHT, $OP, Date64Array) } other => Err(DataFusionError::Internal(format!( - "Data type {:?} not supported for scalar operation on dyn array", - other + "Data type {:?} not supported for scalar operation '{}' on dyn array", + other, stringify!($OP) ))), }; Some(result) @@ -320,8 +321,8 @@ macro_rules! binary_array_op { compute_op!($LEFT, $RIGHT, $OP, Date64Array) } other => Err(DataFusionError::Internal(format!( - "Data type {:?} not supported for binary operation on dyn arrays", - other + "Data type {:?} not supported for binary operation '{}' on dyn arrays", + other, stringify!($OP) ))), } }}; @@ -352,8 +353,8 @@ macro_rules! binary_string_array_flag_op { compute_utf8_flag_op!($LEFT, $RIGHT, $OP, LargeStringArray, $NOT, $FLAG) } other => Err(DataFusionError::Internal(format!( - "Data type {:?} not supported for binary_string_array_flag_op operation on string array", - other + "Data type {:?} not supported for binary_string_array_flag_op operation '{}' on string array", + other, stringify!($OP) ))), } }}; @@ -394,8 +395,8 @@ macro_rules! binary_string_array_flag_op_scalar { compute_utf8_flag_op_scalar!($LEFT, $RIGHT, $OP, LargeStringArray, $NOT, $FLAG) } other => Err(DataFusionError::Internal(format!( - "Data type {:?} not supported for binary_string_array_flag_op_scalar operation on string array", - other + "Data type {:?} not supported for binary_string_array_flag_op_scalar operation '{}' on string array", + other, stringify!($OP) ))), }; Some(result) @@ -420,8 +421,8 @@ macro_rules! compute_utf8_flag_op_scalar { Ok(Arc::new(array)) } else { Err(DataFusionError::Internal(format!( - "compute_utf8_flag_op_scalar failed to cast literal value {}", - $RIGHT + "compute_utf8_flag_op_scalar failed to cast literal value {} for operation '{}'", + $RIGHT, stringify!($OP) ))) } }}; From bb2756455df3ab80314f347a2f14f85eb1f39371 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Thu, 21 Oct 2021 15:01:44 -0400 Subject: [PATCH 2/2] Update error messages in test --- datafusion/src/physical_optimizer/pruning.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/datafusion/src/physical_optimizer/pruning.rs b/datafusion/src/physical_optimizer/pruning.rs index 29a196df1c14a..ba0186513a455 100644 --- a/datafusion/src/physical_optimizer/pruning.rs +++ b/datafusion/src/physical_optimizer/pruning.rs @@ -1382,7 +1382,7 @@ mod tests { let result = p.prune(&statistics).unwrap_err(); assert!( result.to_string().contains( - "Data type Boolean not supported for scalar operation on dyn array" + "Data type Boolean not supported for scalar operation 'lt_eq' on dyn array" ), "{}", result @@ -1399,7 +1399,7 @@ mod tests { let result = p.prune(&statistics).unwrap_err(); assert!( result.to_string().contains( - "Data type Boolean not supported for scalar operation on dyn array" + "Data type Boolean not supported for scalar operation 'lt_eq' on dyn array" ), "{}", result