Skip to content

Apache DataFusion SQL Query Engine

Produce informative error message on insert plan type mismatch (#12540)

Piotr Findeisen4dc7908b372d
diff --git a/datafusion/core/src/datasource/listing/table.rs b/datafusion/core/src/datasource/listing/table.rs
index b91cc74d46..d2c2bd7a12 100644
--- a/datafusion/core/src/datasource/listing/table.rs
+++ b/datafusion/core/src/datasource/listing/table.rs
@@ -907,9 +907,21 @@ impl TableProvider for ListingTable {
.schema()
.logically_equivalent_names_and_types(&input.schema())
{
+ // Return an error if schema of the input query does not match with the table schema.
return plan_err!(
- // Return an error if schema of the input query does not match with the table schema.
- "Inserting query must have the same schema with the table."
+ "Inserting query must have the same schema with the table. \
+ Expected: {:?}, got: {:?}",
+ self.schema()
+ .fields()
+ .iter()
+ .map(|field| field.data_type())
+ .collect::<Vec<_>>(),
+ input
+ .schema()
+ .fields()
+ .iter()
+ .map(|field| field.data_type())
+ .collect::<Vec<_>>()
);
}
diff --git a/datafusion/core/src/datasource/memory.rs b/datafusion/core/src/datasource/memory.rs
index cef7f210e1..70f3c36b81 100644
--- a/datafusion/core/src/datasource/memory.rs
+++ b/datafusion/core/src/datasource/memory.rs
@@ -274,7 +274,19 @@ impl TableProvider for MemTable {
.logically_equivalent_names_and_types(&input.schema())
{
return plan_err!(
- "Inserting query must have the same schema with the table."
+ "Inserting query must have the same schema with the table. \
+ Expected: {:?}, got: {:?}",
+ self.schema()
+ .fields()
+ .iter()
+ .map(|field| field.data_type())
+ .collect::<Vec<_>>(),
+ input
+ .schema()
+ .fields()
+ .iter()
+ .map(|field| field.data_type())
+ .collect::<Vec<_>>()
);
}
if overwrite {