Skip to content

Commit db334ae

Browse files
committed
Fix some incorrect usage of schema
1 parent 7abfee9 commit db334ae

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

pyiceberg/table/__init__.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,8 @@ def upsert(
747747

748748
if join_cols is None:
749749
join_cols = []
750-
for field_id in df.schema.identifier_field_ids:
751-
col = df.schema.find_column_name(field_id)
750+
for field_id in self.table_metadata.schema().identifier_field_ids:
751+
col = self.table_metadata.schema().find_column_name(field_id)
752752
if col is not None:
753753
join_cols.append(col)
754754
else:
@@ -767,12 +767,12 @@ def upsert(
767767

768768
downcast_ns_timestamp_to_us = Config().get_bool(DOWNCAST_NS_TIMESTAMP_TO_US_ON_WRITE) or False
769769
_check_pyarrow_schema_compatible(
770-
df.schema, provided_schema=df.schema, downcast_ns_timestamp_to_us=downcast_ns_timestamp_to_us
770+
self.table_metadata.schema(), provided_schema=df.schema, downcast_ns_timestamp_to_us=downcast_ns_timestamp_to_us
771771
)
772772

773773
# get list of rows that exist so we don't have to load the entire target table
774774
matched_predicate = upsert_util.create_match_filter(df, join_cols)
775-
matched_iceberg_table = df.scan(row_filter=matched_predicate, case_sensitive=case_sensitive).to_arrow()
775+
matched_iceberg_table = self._table.scan(row_filter=matched_predicate, case_sensitive=case_sensitive).to_arrow()
776776

777777
update_row_cnt = 0
778778
insert_row_cnt = 0
@@ -793,7 +793,7 @@ def upsert(
793793

794794
if when_not_matched_insert_all:
795795
expr_match = upsert_util.create_match_filter(matched_iceberg_table, join_cols)
796-
expr_match_bound = bind(df.schema, expr_match, case_sensitive=case_sensitive)
796+
expr_match_bound = bind(self.table_metadata.schema(), expr_match, case_sensitive=case_sensitive)
797797
expr_match_arrow = expression_to_pyarrow(expr_match_bound)
798798
rows_to_insert = df.filter(~expr_match_arrow)
799799

@@ -1270,8 +1270,11 @@ def upsert(
12701270
"""
12711271
with self.transaction() as tx:
12721272
return tx.upsert(
1273-
df=df, join_cols=join_cols, when_matched_update_all=when_matched_update_all, when_not_matched_insert_all=when_not_matched_insert_all,
1274-
case_sensitive=case_sensitive
1273+
df=df,
1274+
join_cols=join_cols,
1275+
when_matched_update_all=when_matched_update_all,
1276+
when_not_matched_insert_all=when_not_matched_insert_all,
1277+
case_sensitive=case_sensitive,
12751278
)
12761279

12771280
def append(self, df: pa.Table, snapshot_properties: Dict[str, str] = EMPTY_DICT) -> None:

0 commit comments

Comments
 (0)