strongduanmu commented on a change in pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504#discussion_r715713321
##########
File path:
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
##########
@@ -63,10 +75,19 @@ protected boolean isGenerateSQLTokenForEncrypt(final
SQLStatementContext sqlStat
@Override
public Collection<SubstitutableColumnNameToken> generateSQLTokens(final
SelectStatementContext selectStatementContext) {
ProjectionsSegment projectionsSegment =
selectStatementContext.getSqlStatement().getProjections();
- // TODO process multiple tables
- String tableName =
selectStatementContext.getAllTables().iterator().next().getTableName().getIdentifier().getValue();
- return getEncryptRule().findEncryptTable(tableName).map(
- encryptTable -> generateSQLTokens(projectionsSegment, tableName,
selectStatementContext, encryptTable)).orElseGet(Collections::emptyList);
+ Collection<SubstitutableColumnNameToken> result = new HashSet<>();
+ Collection<String> tableNames =
selectStatementContext.getTablesContext().getTableNames();
+ for (String each : tableNames) {
+ Optional<EncryptTable> encryptTable =
getEncryptRule().findEncryptTable(each);
+ if (encryptTable.isPresent()) {
+ Collection<SubstitutableColumnNameToken> sqlTokens =
generateSQLTokens(projectionsSegment, each, selectStatementContext,
encryptTable.get());
+ result.addAll(sqlTokens);
+ }
+ }
+ if (selectStatementContext.isContainsJoinQuery()) {
Review comment:
@cheese8 Why do you need to process the associated query separately
instead of in the general generateSQLTokens method above?
##########
File path:
shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/TableExtractor.java
##########
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sql.parser.sql.common.util;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Table extractor.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class TableExtractor {
Review comment:
@cheese8 Please consider move this logic to TablesContext.
##########
File path:
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptPredicateColumnTokenGenerator.java
##########
@@ -66,47 +67,53 @@ protected boolean isGenerateSQLTokenForEncrypt(final
SQLStatementContext sqlStat
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));
- }
+ andPredicates.forEach(each ->
result.addAll(generateSQLTokens(each.getPredicates(), columnTableNames)));
return result;
}
- private Collection<SubstitutableColumnNameToken> generateSQLTokens(final
Collection<ExpressionSegment> predicates, final Map<String, String>
columnTableNames) {
Review comment:
@cheese8 Please keep the original param predicates.
##########
File path:
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptPredicateColumnTokenGenerator.java
##########
@@ -66,47 +67,53 @@ protected boolean isGenerateSQLTokenForEncrypt(final
SQLStatementContext sqlStat
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));
- }
+ andPredicates.forEach(each ->
result.addAll(generateSQLTokens(each.getPredicates(), columnTableNames)));
Review comment:
@cheese8 What is the difference between this change and the original
logic?
--
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]