diff --git a/crates/core/src/operations/cast/mod.rs b/crates/core/src/operations/cast/mod.rs index 554373e623..278cb2bbfa 100644 --- a/crates/core/src/operations/cast/mod.rs +++ b/crates/core/src/operations/cast/mod.rs @@ -144,7 +144,19 @@ fn cast_field( add_missing, )?) as ArrayRef), _ if is_cast_required(col_type, field_type) => { - cast_with_options(col, field_type, cast_options) + cast_with_options(col, field_type, cast_options).map_err(|err| { + if let ArrowError::CastError(err) = err { + ArrowError::CastError(format!( + "Failed to cast {} from {} to {}: {}", + field.name(), + field_type, + col_type, + err + )) + } else { + err + } + }) } _ => Ok(col.clone()), } @@ -337,6 +349,11 @@ mod tests { assert!(!is_cast_required(&field1, &field2)); } + #[test] + fn test_is_cast_required_with_smol_int() { + assert!(is_cast_required(&DataType::Int8, &DataType::Int32)); + } + #[test] fn test_is_cast_required_with_list_non_default_item() { let field1 = DataType::List(FieldRef::from(Field::new("item", DataType::Int32, false))); diff --git a/python/tests/test_writer.py b/python/tests/test_writer.py index c43e5d1136..a6662c48d6 100644 --- a/python/tests/test_writer.py +++ b/python/tests/test_writer.py @@ -273,7 +273,8 @@ def test_write_type_castable_types(existing_table: DeltaTable): engine="rust", ) with pytest.raises( - Exception, match="Cast error: Cannot cast string 'hello' to value of Int8 type" + Exception, + match="Cast error: Failed to cast int8 from Int8 to Utf8: Cannot cast string 'hello' to value of Int8 type", ): write_deltalake( existing_table, @@ -284,7 +285,8 @@ def test_write_type_castable_types(existing_table: DeltaTable): ) with pytest.raises( - Exception, match="Cast error: Can't cast value 1000 to type Int8" + Exception, + match="Cast error: Failed to cast int8 from Int8 to Int64: Can't cast value 1000 to type Int8", ): write_deltalake( existing_table,