Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion datafusion/expr/src/logical_plan/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl LogicalPlanBuilder {
&& !can_cast_types(&data_type, field_type)
{
return exec_err!(
"type mismatch and can't cast to got {} and {}",
"Type mismatch and can't cast, received data of type {} for field of type {}",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original part sounds a bit odd to me. What do you think about "Types don't match and no valid cast exists, ..."

data_type,
field_type
);
Expand Down Expand Up @@ -3034,4 +3034,25 @@ mod tests {
]
);
}

#[test]
fn test_values_with_schema_type_mismatch_error_message() {
// Date32 field, but the value is a Boolean, which cannot be cast to Date32.
let schema = Arc::new(
DFSchema::from_unqualified_fields(
vec![Field::new("a", DataType::Date32, false)].into(),
HashMap::new(),
)
.unwrap(),
);

let err = LogicalPlanBuilder::values_with_schema(vec![vec![lit(true)]], &schema)
.unwrap_err();

assert_eq!(
err.strip_backtrace(),
"Execution error: Type mismatch and can't cast, \
received data of type Boolean for field of type Date32"
);
}
}
Loading