From 44937c89dd1301d495949cb45ee07ddcee9681de Mon Sep 17 00:00:00 2001 From: "josephlenton@gmail.com" Date: Sun, 2 Aug 2026 11:53:47 +0100 Subject: [PATCH 1/3] fix: correct the typo for the builder error type --- datafusion/expr/src/logical_plan/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datafusion/expr/src/logical_plan/builder.rs b/datafusion/expr/src/logical_plan/builder.rs index 1f32d9c6da445..fb722b21d493f 100644 --- a/datafusion/expr/src/logical_plan/builder.rs +++ b/datafusion/expr/src/logical_plan/builder.rs @@ -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 {}", data_type, field_type ); From bd7234cb08e355740e962f087f1cd406a9d49468 Mon Sep 17 00:00:00 2001 From: "josephlenton@gmail.com" Date: Sun, 2 Aug 2026 19:49:34 +0100 Subject: [PATCH 2/3] chore: add a test for the error message --- datafusion/expr/src/logical_plan/builder.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/datafusion/expr/src/logical_plan/builder.rs b/datafusion/expr/src/logical_plan/builder.rs index fb722b21d493f..cd1f21aa800cd 100644 --- a/datafusion/expr/src/logical_plan/builder.rs +++ b/datafusion/expr/src/logical_plan/builder.rs @@ -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" + ); + } } From 8ece65f5f3c39dee6c0660365b80f1287f6953ee Mon Sep 17 00:00:00 2001 From: "josephlenton@gmail.com" Date: Wed, 5 Aug 2026 16:56:29 +0100 Subject: [PATCH 3/3] refactor: update to a clearer error message --- datafusion/expr/src/logical_plan/builder.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/datafusion/expr/src/logical_plan/builder.rs b/datafusion/expr/src/logical_plan/builder.rs index cd1f21aa800cd..a3d2c6e17adf9 100644 --- a/datafusion/expr/src/logical_plan/builder.rs +++ b/datafusion/expr/src/logical_plan/builder.rs @@ -283,7 +283,7 @@ impl LogicalPlanBuilder { && !can_cast_types(&data_type, field_type) { return exec_err!( - "Type mismatch and can't cast, received data of type {} for field of type {}", + "Types don't match and no valid cast exists, received data of type {} for field of type {}", data_type, field_type ); @@ -3051,7 +3051,7 @@ mod tests { assert_eq!( err.strip_backtrace(), - "Execution error: Type mismatch and can't cast, \ + "Execution error: Types don't match and no valid cast exists, \ received data of type Boolean for field of type Date32" ); }