JingsongLi commented on code in PR #5506:
URL: https://github.com/apache/paimon/pull/5506#discussion_r2053344781


##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/clone/hive/ListHiveFilesFunction.java:
##########
@@ -95,6 +118,71 @@ public void processElement(
         }
     }
 
+    private void checkCompatible(Schema sourceSchema, FileStoreTable 
existedTable) {
+        Schema existedSchema = existedTable.schema().toSchema();
+
+        // check primary keys
+        if (!existedSchema.primaryKeys().isEmpty()) {
+            throw new IllegalStateException(
+                    "Can not clone data to existed paimon table which has 
primary keys. Existed paimon table is "
+                            + existedTable.name());
+        }
+
+        // check bucket
+        if (existedTable.coreOptions().bucket() != -1) {
+            throw new IllegalStateException(
+                    "Can not clone data to existed paimon table which bucket 
is not -1. Existed paimon table is "
+                            + existedTable.name());
+        }
+
+        // check partition keys
+        List<DataField> sourcePartitionFields =
+                new ArrayList<>(
+                        TableSchema.create(0, sourceSchema)
+                                
.projectedLogicalRowType(sourceSchema.partitionKeys())
+                                .getFields());
+
+        List<DataField> existedPartitionFields =
+                new ArrayList<>(
+                        existedTable
+                                .schema()
+                                
.projectedLogicalRowType(existedTable.partitionKeys())
+                                .getFields());
+
+        if (sourcePartitionFields.size() != existedPartitionFields.size()) {
+            throw new IllegalStateException(
+                    "size of source table partition keys not equal existed 
paimon table partition keys.");
+        }
+        checkCompatible(sourcePartitionFields, existedPartitionFields);
+
+        // check all fields
+        List<DataField> sourceFields = new ArrayList<>(sourceSchema.fields());
+        List<DataField> existedFields = new 
ArrayList<>(existedSchema.fields());
+
+        if (sourceFields.size() != existedFields.size()) {

Review Comment:
   Since we have very strong schema evolution ability, here maybe we can just 
check contain all field Names.



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