cheese8 commented on a change in pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504#discussion_r717321565



##########
File path: 
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptPredicateColumnTokenGenerator.java
##########
@@ -56,57 +59,82 @@
     
     @Override
     protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext 
sqlStatementContext) {
+        return 
isGenerateSQLTokenForEncryptOnWhereAvailable(sqlStatementContext) || 
isGenerateSQLTokenForEncryptOnJoinSegments(sqlStatementContext);
+    }
+    
+    private boolean isGenerateSQLTokenForEncryptOnWhereAvailable(final 
SQLStatementContext sqlStatementContext) {
         return sqlStatementContext instanceof WhereAvailable && 
((WhereAvailable) sqlStatementContext).getWhere().isPresent();
     }
     
+    private boolean isGenerateSQLTokenForEncryptOnJoinSegments(final 
SQLStatementContext sqlStatementContext) {
+        return sqlStatementContext instanceof SelectStatementContext && 
!WhereExtractUtil.getJoinWhereSegments((SelectStatement) 
sqlStatementContext.getSqlStatement()).isEmpty();
+    }
+    
     @Override
     public Collection<SubstitutableColumnNameToken> generateSQLTokens(final 
SQLStatementContext sqlStatementContext) {
-        Preconditions.checkState(((WhereAvailable) 
sqlStatementContext).getWhere().isPresent());
         Collection<SubstitutableColumnNameToken> result = new 
LinkedHashSet<>();
-        ExpressionSegment expression = ((WhereAvailable) 
sqlStatementContext).getWhere().get().getExpr();
-        Collection<AndPredicate> andPredicates = 
ExpressionExtractUtil.getAndPredicates(expression);
-        Map<String, String> columnTableNames = 
getColumnTableNames(sqlStatementContext, andPredicates);
-        for (AndPredicate each : andPredicates) {
-            result.addAll(generateSQLTokens(each.getPredicates(), 
columnTableNames));
+        Collection<AndPredicate> andPredicates = new LinkedHashSet<>();
+        if (isGenerateSQLTokenForEncryptOnWhereAvailable(sqlStatementContext)) 
{
+            ExpressionSegment expression = ((WhereAvailable) 
sqlStatementContext).getWhere().get().getExpr();
+            
andPredicates.addAll(ExpressionExtractUtil.getAndPredicates(expression));
         }
+        Optional<Collection<WhereSegment>> whereSegments = Optional.empty();
+        if (sqlStatementContext instanceof SelectStatementContext) {
+            whereSegments = 
Optional.of(WhereExtractUtil.getJoinWhereSegments((SelectStatement) 
sqlStatementContext.getSqlStatement()));

Review comment:
       fixed




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