rambleraptor commented on code in PR #3384:
URL: https://github.com/apache/iceberg-python/pull/3384#discussion_r4010208015


##########
pyiceberg/table/__init__.py:
##########
@@ -861,10 +782,46 @@ def upsert(
         if not when_matched_update_all and not when_not_matched_insert_all:
             raise ValueError("no upsert options selected...exiting")
 
-        if upsert_util.has_duplicate_rows(df, join_cols):
-            raise ValueError("Duplicate rows found in source dataset based on 
the key columns. No upsert executed")
+        from pyiceberg.io.pyarrow import _check_pyarrow_schema_compatible, 
schema_to_pyarrow
 
-        from pyiceberg.io.pyarrow import _check_pyarrow_schema_compatible
+        table_arrow_schema = schema_to_pyarrow(self.table_metadata.schema(), 
include_field_ids=False)
+        df_column_names = set(df.schema.names)
+
+        for col in join_cols:
+            if col not in table_arrow_schema.names:
+                raise ValueError(
+                    f"Join column '{col}' does not exist in the table schema. "
+                    f"Available columns: {', 
'.join(table_arrow_schema.names)}."
+                )
+            table_field = table_arrow_schema.field(col)
+            # Table-level rejections: These types are fundamentally unreliable 
or
+            # unsupported as join keys regardless of the input data format.
+            if pa.types.is_floating(table_field.type):
+                raise ValueError(
+                    f"Floating point column '{col}' cannot be used as a join 
key in upsert. "
+                    "Floating point equality is unreliable; please cast to 
Decimal or Integer."
+                )
+            if pa.types.is_nested(table_field.type):
+                raise ValueError(
+                    f"Nested column '{col}' of type '{table_field.type}' 
cannot be used as a join key in upsert. "
+                    "Only primitive types are supported."
+                )
+
+            # Dataframe-level rejections: only validate when the column is 
present in the
+            # source; missing columns are surfaced by 
_check_pyarrow_schema_compatible below.

Review Comment:
   I don't think `_check_pyarrow_schema_compatible` will catch anything for 
optional columns. 
   
   Can you add a test case for this? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to