From 110c8dd491ab03c5e0fd59968fb8c79a78d6b56e Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Fri, 15 Nov 2024 12:31:28 +0100 Subject: [PATCH] Produce informative error on physical schema mismatch Include details that can help understand the problem. --- datafusion/core/src/physical_planner.rs | 36 ++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/datafusion/core/src/physical_planner.rs b/datafusion/core/src/physical_planner.rs index 26f6b12908a7c..1ea4705f1e11b 100644 --- a/datafusion/core/src/physical_planner.rs +++ b/datafusion/core/src/physical_planner.rs @@ -659,7 +659,41 @@ impl DefaultPhysicalPlanner { if &physical_input_schema != physical_input_schema_from_logical && !options.execution.skip_physical_aggregate_schema_check { - return internal_err!("Physical input schema should be the same as the one converted from logical input schema."); + let mut differences = Vec::new(); + if physical_input_schema.fields().len() + != physical_input_schema_from_logical.fields().len() + { + differences.push(format!( + "Different number of fields: (physical) {} vs (logical) {}", + physical_input_schema.fields().len(), + physical_input_schema_from_logical.fields().len() + )); + } + for (i, (physical_field, logical_field)) in physical_input_schema + .fields() + .iter() + .zip(physical_input_schema_from_logical.fields()) + .enumerate() + { + if physical_field.name() != logical_field.name() { + differences.push(format!( + "field name at index {}: (physical) {} vs (logical) {}", + i, + physical_field.name(), + logical_field.name() + )); + } + if physical_field.data_type() != logical_field.data_type() { + differences.push(format!("field data type at index {}: (physical) {} vs (logical) {}", i, physical_field.data_type(), logical_field.data_type())); + } + if physical_field.is_nullable() != logical_field.is_nullable() { + differences.push(format!("field nullability at index {}: (physical) {} vs (logical) {}", i, physical_field.is_nullable(), logical_field.is_nullable())); + } + } + return internal_err!("Physical input schema should be the same as the one converted from logical input schema. Differences: {}", differences + .iter() + .map(|s| format!("\n\t- {}", s)) + .join("")); } let groups = self.create_grouping_physical_expr(