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/2] 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/2] 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" + ); + } }