sandynz commented on code in PR #20944:
URL: https://github.com/apache/shardingsphere/pull/20944#discussion_r969073932


##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationDataConsistencyChecker.java:
##########
@@ -179,7 +180,14 @@ private Map<String, DataConsistencyContentCheckResult> 
checkData(final DataConsi
                     throw new PipelineDataConsistencyCheckFailedException("Can 
not get metadata for table " + each);
                 }
                 Collection<String> columnNames = 
tableMetaData.getColumnNames();
-                PipelineColumnMetaData uniqueKey = 
tableMetaData.getColumnMetaData(tableMetaData.getPrimaryKeyColumns().get(0));
+                PipelineColumnMetaData uniqueKey;
+                if (!tableMetaData.getPrimaryKeyColumns().isEmpty()) {
+                    uniqueKey = 
tableMetaData.getColumnMetaData(tableMetaData.getPrimaryKeyColumns().get(0));
+                } else {
+                    PipelineIndexMetaData pipelineIndexMetaData = 
tableMetaData.getUniqueIndexes().stream().filter(index -> 
index.getColumns().size() == 1).findFirst()
+                            .orElseThrow(() -> new 
PipelineDataConsistencyCheckFailedException("No support, neither the primary 
key and the unique key exist."));
+                    uniqueKey = 
tableMetaData.getColumnMetaData(pipelineIndexMetaData.getColumns().get(0).getOrdinalPosition());
+                }

Review Comment:
   1, Could we put these code in unified method? Seems there's similar code in 
InventoryTaskSplitter.
   
   2, Is it possible to persist unique key in job configuration?
   



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