Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/cargo/reqwest-0.12.5
Browse files Browse the repository at this point in the history
  • Loading branch information
rtyler committed Jun 26, 2024
2 parents d51c4bb + d9605ea commit 36f8a0e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/core/src/operations/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,13 @@ impl std::future::IntoFuture for WriteBuilder {
try_cast_batch(schema.fields(), table_schema.fields())
{
schema_drift = true;
if this.mode == SaveMode::Overwrite && this.schema_mode.is_some() {
if this.mode == SaveMode::Overwrite
&& this.schema_mode == Some(SchemaMode::Merge)
{
new_schema =
Some(merge_schema(table_schema.clone(), schema.clone())?);
} else if this.mode == SaveMode::Overwrite && this.schema_mode.is_some()
{
new_schema = None // we overwrite anyway, so no need to cast
} else if this.schema_mode == Some(SchemaMode::Merge) {
new_schema =
Expand Down
28 changes: 28 additions & 0 deletions python/tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,34 @@ def test_update_schema_rust_writer_invalid(existing_table: DeltaTable):
assert existing_table.schema().to_pyarrow() == new_data.schema


def test_merge_schema_rust_writer_with_overwrite(tmp_path: pathlib.Path):
data = pa.table(
{
"a": pa.array([1, 2, 3, 4]),
"b": pa.array([1, 1, 2, 2]),
"c": pa.array([10, 11, 12, 13]),
}
)
write_deltalake(
tmp_path,
data,
engine="rust",
)

new_data = pa.table({"a": pa.array([100, 200, 300]), "b": pa.array([1, 1, 1])})

write_deltalake(
tmp_path,
new_data,
mode="overwrite",
schema_mode="merge",
engine="rust",
)
assert set(DeltaTable(tmp_path).to_pyarrow_table().column_names) == set(
["a", "b", "c"]
)


@pytest.mark.parametrize("engine", ["pyarrow", "rust"])
def test_local_path(
tmp_path: pathlib.Path,
Expand Down

0 comments on commit 36f8a0e

Please sign in to comment.