Copilot commented on code in PR #7566:
URL: https://github.com/apache/paimon/pull/7566#discussion_r3015671884


##########
paimon-api/src/main/java/org/apache/paimon/schema/SchemaChange.java:
##########
@@ -810,6 +817,25 @@ public int hashCode() {
         }
     }
 
+    /** A SchemaChange to drop primary keys. */
+    final class DropPrimaryKeys implements SchemaChange {
+
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) {
+                return true;
+            }
+            return o != null && getClass() == o.getClass();
+        }
+
+        @Override
+        public int hashCode() {
+            return 0;

Review Comment:
   `DropPrimaryKeys.hashCode()` currently always returns 0. While this is 
consistent with the `equals` implementation, it causes worst-case behavior in 
hash-based collections and is inconsistent with the rest of the change classes 
which generally compute a non-constant hash. Prefer returning a stable 
per-class hash (e.g., `getClass().hashCode()` or `Objects.hash(getClass())`).
   ```suggestion
               return getClass().hashCode();
   ```



##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/FlinkCatalog.java:
##########
@@ -627,6 +627,9 @@ private List<SchemaChange> toSchemaChange(
         } else if (change instanceof MaterializedTableChange
                 && handleMaterializedTableChange(change, schemaChanges)) {
             return schemaChanges;
+        } else if (change instanceof TableChange.DropConstraint) {
+            schemaChanges.add(SchemaChange.dropPrimaryKeys());
+            return schemaChanges;

Review Comment:
   `TableChange.DropConstraint` is mapped unconditionally to 
`SchemaChange.dropPrimaryKeys()`. Since `DropConstraint` is a generic Flink 
change type, this will also drop primary keys if Flink emits a drop for some 
other constraint type (now or in future Flink versions). Consider verifying the 
dropped constraint corresponds to the table primary key (e.g., compare old/new 
schemas’ PK presence and/or constraint name) before applying `dropPrimaryKeys`, 
otherwise reject unsupported constraint drops explicitly.
   ```suggestion
               TableChange.DropConstraint dropConstraint = 
(TableChange.DropConstraint) change;
               throw new UnsupportedOperationException(
                       "Drop constraint change is not supported: " + 
dropConstraint.getConstraintName());
   ```



-- 
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]

Reply via email to