RaigorJiang commented on a change in pull request #15439:
URL: https://github.com/apache/shardingsphere/pull/15439#discussion_r807765618



##########
File path: 
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java
##########
@@ -64,18 +68,29 @@ private void checkCurrentRuleConfiguration(final String 
schemaName, final Encryp
         }
     }
     
-    private void checkToBeAlteredRules(final String schemaName, final 
AlterEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration 
currentRuleConfig) throws RequiredRuleMissedException {
+    private void checkToBeAlteredRules(final String schemaName, final 
AlterEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration 
currentRuleConfig) throws DistSQLException {
         Collection<String> currentEncryptTableNames = 
currentRuleConfig.getTables().stream().map(EncryptTableRuleConfiguration::getName).collect(Collectors.toList());
         Collection<String> notExistEncryptTableNames = 
getToBeAlteredEncryptTableNames(sqlStatement).stream().filter(each -> 
!currentEncryptTableNames.contains(each)).collect(Collectors.toList());
         if (!notExistEncryptTableNames.isEmpty()) {
             throw new RequiredRuleMissedException("Encrypt", schemaName, 
notExistEncryptTableNames);
         }
+        checkDataType(sqlStatement);
     }
     
     private Collection<String> getToBeAlteredEncryptTableNames(final 
AlterEncryptRuleStatement sqlStatement) {
         return 
sqlStatement.getRules().stream().map(EncryptRuleSegment::getTableName).collect(Collectors.toList());
     }
     
+    private void checkDataType(final AlterEncryptRuleStatement sqlStatement) 
throws DistSQLException {
+        Collection<String> invalidRules = sqlStatement.getRules().stream()
+                .map(each -> getInvalidColumns(each.getTableName(), 
each.getColumns())).flatMap(Collection::stream).collect(Collectors.toCollection(LinkedList::new));
+        DistSQLException.predictionThrow(invalidRules.isEmpty(), new 
InvalidRuleConfigurationException("encrypt", invalidRules, 
Collections.singleton("incomplete data type")));
+    }
+    
+    private Collection<String> getInvalidColumns(final String tableName, final 
Collection<EncryptColumnSegment> columns) {
+        return columns.stream().filter(each1 -> 
!each1.isCorrectDataType()).map(each1 -> String.format("%s.%s", tableName, 
each1.getName())).collect(Collectors.toCollection(LinkedList::new));

Review comment:
       `each1` is not a good name here. 




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