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


##########
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:
   I did some local tests, schema evolution ability in paimon is really strong! 
Even if the datatypes of partition fields are different, the target paimon 
table performing clone action can be read normally. I will simplify the check 
conditions!



-- 
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: issues-unsubscr...@paimon.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to