Skip to content

Commit

Permalink
chore: add a reproduction case for merge failures with struct<string>
Browse files Browse the repository at this point in the history
  • Loading branch information
rtyler committed Jul 3, 2024
1 parent 7adddc9 commit b871cbd
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions python/tests/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,3 +940,47 @@ def test_merge_field_special_characters_delete_2438(tmp_path: pathlib.Path):
expected = pa.table({"x": [1], "y--1": [4]})

assert dt.to_pyarrow_table() == expected


@pytest.mark.pandas
def test_struct_casting(tmp_path: pathlib.Path):
import pandas as pd

cols = ["id", "name", "address", "scores"]
data = [
(
2,
"Marry Doe",
{"street": "123 Main St", "city": "Anytown", "state": "CA"},
[0, 0, 0],
)
]
df = pd.DataFrame(data, columns=cols)
df_merge = pd.DataFrame(
[
(
2,
"Merged",
{"street": "1 Front", "city": "San Francisco", "state": "CA"},
[7, 0, 7],
)
],
columns=cols,
)
assert not df.empty

schema = pa.Table.from_pandas(df=df).schema

dt = DeltaTable.create(tmp_path, schema, name="test")
metadata = dt.metadata()
assert metadata.name == "test"

result = (
dt.merge(
source=df_merge, predicate="t.id = s.id", source_alias="s", target_alias="t"
)
.when_matched_update_all()
.when_not_matched_insert_all()
.execute()
)
assert result is not None

0 comments on commit b871cbd

Please sign in to comment.