Skip to content

Commit

Permalink
Improve error messages when operations are not supported (#1158)
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb authored Oct 22, 2021
1 parent 2b002e4 commit e6657f0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions datafusion/src/physical_optimizer/pruning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
39 changes: 20 additions & 19 deletions datafusion/src/physical_plan/expressions/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)))
}
Expand Down Expand Up @@ -171,8 +172,8 @@ macro_rules! binary_string_array_op_scalar {
let result: Result<Arc<dyn Array>> = 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)
Expand All @@ -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)
))),
}
}};
Expand All @@ -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)
))),
}
}};
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
))),
}
}};
Expand Down Expand Up @@ -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)
))),
}
}};
Expand Down Expand Up @@ -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)
Expand All @@ -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)
)))
}
}};
Expand Down

0 comments on commit e6657f0

Please sign in to comment.