Repository navigation
Align upsert targets to the source schema - #4551
Open
Anurag-S1ngh wants to merge 1 commit into
Open
Anurag-S1ngh wants to merge 1 commit into
Anurag-S1ngh wants to merge 1 commit into
Conversation
Scans of files written before a column was added omit that column, so casting the source table to the target schema raised a schema mismatch. Align the target columns by name and add missing ones as nulls.
|
A valid float32 update can return import pyarrow as pa
from pyiceberg.catalog.sql import SqlCatalog
def test_upsert_with_float32_input(tmp_path):
catalog = SqlCatalog("local", uri="sqlite:///:memory:", warehouse=tmp_path.as_uri())
catalog.create_namespace("db")
old = pa.table({"id": [1], "v": pa.array([16777217], type=pa.float64())})
table = catalog.create_table("db.t", schema=old.schema)
table.append(old)
new = pa.table({"id": [1], "v": pa.array([16777216], type=pa.float32())})
result = table.upsert(new, join_cols=["id"])
stored = catalog.load_table("db.t").scan().to_arrow()["v"].to_pylist()
assert (result.rows_updated, stored) == (1, [16777216.0])The test passes on base AI assistance: Codex helped trace the change, run the test on both revisions, and draft this comment. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3105
Rationale for this change
get_rows_to_updatecast the whole source table to the schema of the scanned target rows. A scan of a data file written before a column was added omits that column, so afterupdate_schema().union_by_name()the cast failed with:Align the target rows to the source schema by column name and add any missing source columns as nulls before the join and comparison. The join now selects only the join columns instead of casting the entire table.
This also handles source columns in a different order, which previously failed for the same reason.
Are these changes tested?
pytest tests/table/test_upsert.py(30 passed)ruff checkandruff format --checkon the changed filesAre there any user-facing changes?
No API change. Upsert now succeeds after a schema evolution that adds a column.