This is an automated email from the ASF dual-hosted git repository.

panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 6e00dca  Support table level `queryWithCipherColumn` configuration 
(#13180)
6e00dca is described below

commit 6e00dcab0699b823e7f3641d5ea338fb64e33547
Author: Guocheng Tang <[email protected]>
AuthorDate: Mon Oct 25 18:19:11 2021 +0800

    Support table level `queryWithCipherColumn` configuration (#13180)
    
    * Support table level `queryWithCipherColumn` configuration
    
    * Fix test case
    
    * Fix test case
    
    * Fix test case
    
    * Fix test case
    
    * Fix compile
    
    * fix
    
    * Optimize judgment logic
    
    * fix code style
    
    * fix code style
---
 .../spring-boot-starter/encrypt.cn.md              |  1 +
 .../spring-boot-starter/encrypt.en.md              |  1 +
 .../configuration/spring-namespace/encrypt.cn.md   |  9 ++++----
 .../configuration/spring-namespace/encrypt.en.md   |  9 ++++----
 .../config/local/LocalEncryptConfiguration.java    |  2 +-
 .../jdbc/config/EncryptDatabasesConfiguration.java |  2 +-
 .../jdbc/config/ShadowEncryptConfiguration.java    |  2 +-
 .../config/rule/EncryptTableRuleConfiguration.java |  2 ++
 .../merge/EncryptResultDecoratorEngine.java        |  2 +-
 .../context/EncryptSQLRewriteContextDecorator.java |  3 ++-
 .../impl/EncryptPredicateColumnTokenGenerator.java |  3 ++-
 .../shardingsphere/encrypt/rule/EncryptRule.java   | 24 ++++++++++++++++++++++
 .../shardingsphere/encrypt/rule/EncryptTable.java  |  5 +++++
 .../rule/YamlEncryptTableRuleConfiguration.java    |  2 ++
 .../EncryptTableRuleConfigurationYamlSwapper.java  |  3 ++-
 .../merge/EncryptResultDecoratorEngineTest.java    |  3 ++-
 .../encrypt/rule/EncryptRuleTest.java              |  8 ++++----
 .../encrypt/rule/EncryptTableTest.java             |  2 +-
 ...orithmProviderConfigurationYamlSwapperTest.java |  2 +-
 .../EncryptRuleConfigurationYamlSwapperTest.java   |  2 +-
 ...cryptTableRuleConfigurationYamlSwapperTest.java |  2 +-
 .../converter/EncryptRuleStatementConverter.java   |  2 +-
 .../EncryptRuleStatementConverterTest.java         |  2 +-
 .../query/EncryptRuleQueryResultSetTest.java       |  2 +-
 .../AlterEncryptRuleStatementUpdaterTest.java      |  4 ++--
 .../CreateEncryptRuleStatementUpdaterTest.java     |  4 ++--
 .../DropEncryptRuleStatementUpdaterTest.java       |  6 +++---
 .../core/EncryptDistSQLStatementVisitor.java       |  3 ++-
 .../distsql/parser/segment/EncryptRuleSegment.java |  2 ++
 .../spring/boot/EncryptSpringBootStarterTest.java  |  1 +
 .../test/resources/application-encrypt.properties  |  1 +
 .../parser/EncryptRuleBeanDefinitionParser.java    |  1 +
 .../main/resources/META-INF/namespace/encrypt.xsd  |  1 +
 .../namespace/EncryptSpringNamespaceTest.java      |  1 +
 .../spring/encrypt-application-context.xml         |  2 +-
 35 files changed, 85 insertions(+), 36 deletions(-)

diff --git 
a/docs/document/content/user-manual/shardingsphere-jdbc/configuration/spring-boot-starter/encrypt.cn.md
 
b/docs/document/content/user-manual/shardingsphere-jdbc/configuration/spring-boot-starter/encrypt.cn.md
index fdcc772..92a6464 100644
--- 
a/docs/document/content/user-manual/shardingsphere-jdbc/configuration/spring-boot-starter/encrypt.cn.md
+++ 
b/docs/document/content/user-manual/shardingsphere-jdbc/configuration/spring-boot-starter/encrypt.cn.md
@@ -8,6 +8,7 @@ weight = 3
 ```properties
 spring.shardingsphere.datasource.names= # 省略数据源配置,请参考使用手册
 
+spring.shardingsphere.rules.encrypt.tables.<table-name>.query-with-cipher-column=
 # 该表是否使用加密列进行查询
 
spring.shardingsphere.rules.encrypt.tables.<table-name>.columns.<column-name>.cipher-column=
 # 加密列名称
 
spring.shardingsphere.rules.encrypt.tables.<table-name>.columns.<column-name>.assisted-query-column=
 # 查询列名称
 
spring.shardingsphere.rules.encrypt.tables.<table-name>.columns.<column-name>.plain-column=
 # 原文列名称
diff --git 
a/docs/document/content/user-manual/shardingsphere-jdbc/configuration/spring-boot-starter/encrypt.en.md
 
b/docs/document/content/user-manual/shardingsphere-jdbc/configuration/spring-boot-starter/encrypt.en.md
index 7b4535f..2c685e5 100644
--- 
a/docs/document/content/user-manual/shardingsphere-jdbc/configuration/spring-boot-starter/encrypt.en.md
+++ 
b/docs/document/content/user-manual/shardingsphere-jdbc/configuration/spring-boot-starter/encrypt.en.md
@@ -8,6 +8,7 @@ weight = 3
 ```properties
 spring.shardingsphere.datasource.names= # Omit the data source configuration, 
please refer to the usage
 
+spring.shardingsphere.rules.encrypt.tables.<table-name>.query-with-cipher-column=
 # Whether the table uses cipher columns for query
 
spring.shardingsphere.rules.encrypt.tables.<table-name>.columns.<column-name>.cipher-column=
 # Cipher column name
 
spring.shardingsphere.rules.encrypt.tables.<table-name>.columns.<column-name>.assisted-query-column=
 # Assisted query column name
 
spring.shardingsphere.rules.encrypt.tables.<table-name>.columns.<column-name>.plain-column=
 # Plain column name
diff --git 
a/docs/document/content/user-manual/shardingsphere-jdbc/configuration/spring-namespace/encrypt.cn.md
 
b/docs/document/content/user-manual/shardingsphere-jdbc/configuration/spring-namespace/encrypt.cn.md
index eb755b0..f3088cb 100644
--- 
a/docs/document/content/user-manual/shardingsphere-jdbc/configuration/spring-namespace/encrypt.cn.md
+++ 
b/docs/document/content/user-manual/shardingsphere-jdbc/configuration/spring-namespace/encrypt.cn.md
@@ -17,10 +17,11 @@ weight = 3
 
 \<encrypt:table />
 
-| *名称*     | *类型* | *说明*    |
-| ---------- | ----- | -------- |
-| name       | 属性  | 加密表名称 |
-| column (+) | 标签  | 加密列配置 |
+| *名称*                       | *类型* | *说明*                                     
                 |
+| --------------------------- | ------ | 
---------------------------------------------------------- |
+| name                        | 属性    | 加密表名称                                  
                 |
+| column (+)                  | 标签    | 加密列配置                                  
                 |
+| query-with-cipher-column(?) | 属性    | 该表是否使用加密列进行查询。在有原文列的情况下,可以使用原文列进行查询 |
 
 \<encrypt:column />
 
diff --git 
a/docs/document/content/user-manual/shardingsphere-jdbc/configuration/spring-namespace/encrypt.en.md
 
b/docs/document/content/user-manual/shardingsphere-jdbc/configuration/spring-namespace/encrypt.en.md
index 8fcd358..c848b6c 100644
--- 
a/docs/document/content/user-manual/shardingsphere-jdbc/configuration/spring-namespace/encrypt.en.md
+++ 
b/docs/document/content/user-manual/shardingsphere-jdbc/configuration/spring-namespace/encrypt.en.md
@@ -17,10 +17,11 @@ Namespace: 
[http://shardingsphere.apache.org/schema/shardingsphere/encrypt/encry
 
 \<encrypt:table />
 
-| *Name*    | *Type*     | *Description*                |
-| --------- | ---------- | ---------------------------- |
-| name       | Attribute | Encrypt table name           |
-| column (+) | Tag       | Encrypt column configuration |
+| *Name*                          | *Type*    | *Description*                  
                                                                          |
+| ------------------------------- | --------- | 
--------------------------------------------------------------------------------------------------------
 |
+| name                            | Attribute | Encrypt table name             
                                                                          |
+| column (+)                      | Tag       | Encrypt column configuration   
                                                                          |
+| query-with-cipher-column(?) (?) | Attribute | Whether the table query with 
cipher column for data encrypt. User you can use plaintext to query if have |
 
 \<encrypt:column />
 
diff --git 
a/examples/shardingsphere-jdbc-example/single-feature-example/cluster-mode-example/cluster-mode-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/cluster/mode/raw/jdbc/config/local/LocalEncryptConfiguration.java
 
b/examples/shardingsphere-jdbc-example/single-feature-example/cluster-mode-example/cluster-mode-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/cluster/mode/raw/jdbc/config/local/LocalEncryptConfiguration.java
index 80164e4..b43ea02 100644
--- 
a/examples/shardingsphere-jdbc-example/single-feature-example/cluster-mode-example/cluster-mode-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/cluster/mode/raw/jdbc/config/local/LocalEncryptConfiguration.java
+++ 
b/examples/shardingsphere-jdbc-example/single-feature-example/cluster-mode-example/cluster-mode-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/cluster/mode/raw/jdbc/config/local/LocalEncryptConfiguration.java
@@ -51,7 +51,7 @@ public final class LocalEncryptConfiguration implements 
ExampleConfiguration {
     
     private EncryptTableRuleConfiguration 
createEncryptTableRuleConfiguration() {
         EncryptColumnRuleConfiguration encryptColumnRuleConfig = new 
EncryptColumnRuleConfiguration("status", "status", "", "", "status_encryptor");
-        return new EncryptTableRuleConfiguration("t_order", 
Collections.singleton(encryptColumnRuleConfig));
+        return new EncryptTableRuleConfiguration("t_order", 
Collections.singleton(encryptColumnRuleConfig), null);
     }
     
     private ShardingSphereAlgorithmConfiguration 
createEncryptAlgorithmConfiguration() {
diff --git 
a/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/raw/jdbc/config/EncryptDatabasesConfiguration.java
 
b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/raw/jdbc/config/EncryptDatabasesConfiguration.java
index 3ef5309..0359a93 100644
--- 
a/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/raw/jdbc/config/EncryptDatabasesConfiguration.java
+++ 
b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/raw/jdbc/config/EncryptDatabasesConfiguration.java
@@ -41,7 +41,7 @@ public final class EncryptDatabasesConfiguration implements 
ExampleConfiguration
         props.setProperty("aes-key-value", "123456");
         EncryptColumnRuleConfiguration columnConfigAes = new 
EncryptColumnRuleConfiguration("user_name", "user_name", "", "user_name_plain", 
"name_encryptor");
         EncryptColumnRuleConfiguration columnConfigTest = new 
EncryptColumnRuleConfiguration("pwd", "pwd", "assisted_query_pwd", "", 
"pwd_encryptor");
-        EncryptTableRuleConfiguration encryptTableRuleConfig = new 
EncryptTableRuleConfiguration("t_user", Arrays.asList(columnConfigAes, 
columnConfigTest));
+        EncryptTableRuleConfiguration encryptTableRuleConfig = new 
EncryptTableRuleConfiguration("t_user", Arrays.asList(columnConfigAes, 
columnConfigTest), null);
         Map<String, ShardingSphereAlgorithmConfiguration> 
encryptAlgorithmConfigs = new LinkedHashMap<>(2, 1);
         encryptAlgorithmConfigs.put("name_encryptor", new 
ShardingSphereAlgorithmConfiguration("AES", props));
         encryptAlgorithmConfigs.put("pwd_encryptor", new 
ShardingSphereAlgorithmConfiguration("assistedTest", props));
diff --git 
a/examples/shardingsphere-jdbc-example/single-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/raw/jdbc/config/ShadowEncryptConfiguration.java
 
b/examples/shardingsphere-jdbc-example/single-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/raw/jdbc/config/ShadowEncryptConfiguration.java
index 9d9d2d7..445f281 100644
--- 
a/examples/shardingsphere-jdbc-example/single-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/raw/jdbc/config/ShadowEncryptConfiguration.java
+++ 
b/examples/shardingsphere-jdbc-example/single-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/raw/jdbc/config/ShadowEncryptConfiguration.java
@@ -83,7 +83,7 @@ public final class ShadowEncryptConfiguration extends 
BaseShadowConfiguration {
         Collection<EncryptColumnRuleConfiguration> columns = new 
LinkedList<>();
         columns.add(new EncryptColumnRuleConfiguration("user_name", 
"user_name", "", "user_name_plain", "name_encryptor"));
         columns.add(new EncryptColumnRuleConfiguration("pwd", "pwd", 
"assisted_query_pwd", "", "pwd_encryptor"));
-        result.add(new EncryptTableRuleConfiguration("t_user", columns));
+        result.add(new EncryptTableRuleConfiguration("t_user", columns, null));
         return result;
     }
     
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/rule/EncryptTableRuleConfiguration.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/rule/EncryptTableRuleConfiguration.java
index f4d1935..00cd22a 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/rule/EncryptTableRuleConfiguration.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/rule/EncryptTableRuleConfiguration.java
@@ -32,4 +32,6 @@ public final class EncryptTableRuleConfiguration {
     private final String name;
     
     private final Collection<EncryptColumnRuleConfiguration> columns;
+    
+    private final Boolean queryWithCipherColumn;
 }
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/merge/EncryptResultDecoratorEngine.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/merge/EncryptResultDecoratorEngine.java
index 397a35d..664c712 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/merge/EncryptResultDecoratorEngine.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/merge/EncryptResultDecoratorEngine.java
@@ -42,7 +42,7 @@ public final class EncryptResultDecoratorEngine implements 
ResultDecoratorEngine
                                        final EncryptRule encryptRule, final 
ConfigurationProperties props, final SQLStatementContext sqlStatementContext) {
         if (sqlStatementContext instanceof SelectStatementContext) {
             return new EncryptDQLResultDecorator(new 
EncryptAlgorithmMetaData(schema, 
-                    encryptRule, (SelectStatementContext) 
sqlStatementContext), encryptRule.isQueryWithCipherColumn());
+                    encryptRule, (SelectStatementContext) 
sqlStatementContext), encryptRule.isQueryWithCipherColumn(sqlStatementContext));
         } 
         if (sqlStatementContext.getSqlStatement() instanceof DALStatement) {
             return new EncryptDALResultDecorator();
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecorator.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecorator.java
index 5ee129d..66db4ba 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecorator.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecorator.java
@@ -35,7 +35,8 @@ public final class EncryptSQLRewriteContextDecorator 
implements SQLRewriteContex
     @SuppressWarnings("unchecked")
     @Override
     public void decorate(final EncryptRule encryptRule, final 
ConfigurationProperties props, final SQLRewriteContext sqlRewriteContext, final 
RouteContext routeContext) {
-        for (ParameterRewriter each : new 
EncryptParameterRewriterBuilder(encryptRule, 
encryptRule.isQueryWithCipherColumn()).getParameterRewriters(sqlRewriteContext.getSchema()))
 {
+        for (ParameterRewriter each : new 
EncryptParameterRewriterBuilder(encryptRule, 
encryptRule.isQueryWithCipherColumn(sqlRewriteContext.getSqlStatementContext()))
+                .getParameterRewriters(sqlRewriteContext.getSchema())) {
             if (!sqlRewriteContext.getParameters().isEmpty() && 
each.isNeedRewrite(sqlRewriteContext.getSqlStatementContext())) {
                 each.rewrite(sqlRewriteContext.getParameterBuilder(), 
sqlRewriteContext.getSqlStatementContext(), sqlRewriteContext.getParameters());
             }
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptPredicateColumnTokenGenerator.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptPredicateColumnTokenGenerator.java
index 676d584..8bb6ffd 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptPredicateColumnTokenGenerator.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptPredicateColumnTokenGenerator.java
@@ -83,7 +83,8 @@ public final class EncryptPredicateColumnTokenGenerator 
extends BaseEncryptSQLTo
                 }
                 int startIndex = column.getOwner().isPresent() ? 
column.getOwner().get().getStopIndex() + 2 : column.getStartIndex();
                 int stopIndex = column.getStopIndex();
-                if (!queryWithCipherColumn) {
+                EncryptTable table = encryptTable.get();
+                if (Boolean.FALSE.equals(table.getQueryWithCipherColumn()) || 
!queryWithCipherColumn) {
                     Optional<String> plainColumn = 
encryptTable.get().findPlainColumn(column.getIdentifier().getValue());
                     if (plainColumn.isPresent()) {
                         result.add(new 
SubstitutableColumnNameToken(startIndex, stopIndex, 
getColumnProjections(plainColumn.get())));
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
index ab8af3f..8c28b93 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
@@ -27,10 +27,14 @@ import 
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfigu
 import org.apache.shardingsphere.encrypt.rewrite.util.EncryptPropertiesBuilder;
 import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
 import org.apache.shardingsphere.encrypt.spi.QueryAssistedEncryptAlgorithm;
+import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
+import 
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.binder.type.TableAvailable;
 import 
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmFactory;
 import org.apache.shardingsphere.infra.rule.identifier.scope.SchemaRule;
 import org.apache.shardingsphere.infra.rule.identifier.type.TableContainedRule;
 import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
 
 import java.util.Collection;
 import java.util.Collections;
@@ -242,6 +246,26 @@ public final class EncryptRule implements SchemaRule, 
TableContainedRule {
         Optional<String> originColumnName = findOriginColumnName(logicTable, 
logicColumn);
         return originColumnName.isPresent() && tables.containsKey(logicTable) 
? tables.get(logicTable).findPlainColumn(originColumnName.get()) : 
Optional.empty();
     }
+
+    /**
+     * Check the table is support QueryWithCipherColumn.
+     *
+     * @param sqlStatementContext sqlStatementContext
+     * @return isQueryWithCipherColumn
+     */
+    public boolean isQueryWithCipherColumn(final SQLStatementContext<?> 
sqlStatementContext) {
+        Collection<SimpleTableSegment> simpleTables = sqlStatementContext 
instanceof SelectStatementContext
+                ? ((TableAvailable) sqlStatementContext).getAllTables()
+                : Collections.emptyList();
+        boolean result = queryWithCipherColumn;
+        if (!simpleTables.isEmpty()) {
+            String tableName = 
simpleTables.iterator().next().getTableName().getIdentifier().getValue();
+            if (tables.containsKey(tableName) && null != 
tables.get(tableName).getQueryWithCipherColumn()) {
+                result = tables.get(tableName).getQueryWithCipherColumn();
+            }
+        }
+        return result;
+    }
     
     private Optional<String> findOriginColumnName(final String logicTable, 
final String logicColumn) {
         for (String each : tables.get(logicTable).getLogicColumns()) {
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTable.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTable.java
index 2f08fec..b249d97 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTable.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTable.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.encrypt.rule;
 
 import com.google.common.collect.Maps;
+import lombok.Getter;
 import 
org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
 import 
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
 import org.apache.shardingsphere.infra.exception.ShardingSphereException;
@@ -36,11 +37,15 @@ public final class EncryptTable {
     
     private final Map<String, EncryptColumn> columns;
     
+    @Getter
+    private final Boolean queryWithCipherColumn;
+    
     public EncryptTable(final EncryptTableRuleConfiguration config) {
         columns = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
         for (EncryptColumnRuleConfiguration each : config.getColumns()) {
             columns.put(each.getLogicColumn(), new 
EncryptColumn(each.getCipherColumn(), each.getAssistedQueryColumn(), 
each.getPlainColumn(), each.getEncryptorName()));
         }
+        queryWithCipherColumn = config.getQueryWithCipherColumn();
     }
     
     /**
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlEncryptTableRuleConfiguration.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlEncryptTableRuleConfiguration.java
index 99b62b9..939bfe0 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlEncryptTableRuleConfiguration.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlEncryptTableRuleConfiguration.java
@@ -34,4 +34,6 @@ public final class YamlEncryptTableRuleConfiguration 
implements YamlConfiguratio
     private String name;
     
     private Map<String, YamlEncryptColumnRuleConfiguration> columns = new 
LinkedHashMap<>();
+    
+    private Boolean queryWithCipherColumn;
 }
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/EncryptTableRuleConfigurationYamlSwapper.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/EncryptTableRuleConfigurationYamlSwapper.java
index f43b118..80fe439 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/EncryptTableRuleConfigurationYamlSwapper.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/EncryptTableRuleConfigurationYamlSwapper.java
@@ -40,6 +40,7 @@ public final class EncryptTableRuleConfigurationYamlSwapper 
implements YamlConfi
         for (EncryptColumnRuleConfiguration each : data.getColumns()) {
             result.getColumns().put(each.getLogicColumn(), 
columnYamlSwapper.swapToYamlConfiguration(each));
         }
+        result.setQueryWithCipherColumn(data.getQueryWithCipherColumn());
         return result;
     }
     
@@ -51,6 +52,6 @@ public final class EncryptTableRuleConfigurationYamlSwapper 
implements YamlConfi
             yamlEncryptColumnRuleConfig.setLogicColumn(entry.getKey());
             
columns.add(columnYamlSwapper.swapToObject(yamlEncryptColumnRuleConfig));
         }
-        return new EncryptTableRuleConfiguration(yamlConfig.getName(), 
columns);
+        return new EncryptTableRuleConfiguration(yamlConfig.getName(), 
columns, yamlConfig.getQueryWithCipherColumn());
     }
 }
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/EncryptResultDecoratorEngineTest.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/EncryptResultDecoratorEngineTest.java
index b353baf..a93bcf0 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/EncryptResultDecoratorEngineTest.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/EncryptResultDecoratorEngineTest.java
@@ -43,6 +43,7 @@ import java.util.Collections;
 
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -65,7 +66,7 @@ public final class EncryptResultDecoratorEngineTest {
     @Test
     public void assertNewInstanceWithSelectStatement() {
         EncryptResultDecoratorEngine engine = (EncryptResultDecoratorEngine) 
OrderedSPIRegistry.getRegisteredServices(ResultProcessEngine.class, 
Collections.singleton(rule)).get(rule);
-        ResultDecorator actual = engine.newInstance(databaseType, schema, 
rule, mock(ConfigurationProperties.class), mock(SelectStatementContext.class));
+        ResultDecorator actual = engine.newInstance(databaseType, schema, 
rule, mock(ConfigurationProperties.class), mock(SelectStatementContext.class, 
RETURNS_DEEP_STUBS));
         assertThat(actual, instanceOf(EncryptDQLResultDecorator.class));
     }
     
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java
index e88b940..1a3dff3 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java
@@ -43,7 +43,7 @@ public final class EncryptRuleTest {
     @Test
     public void 
assertNewInstanceWithAlgorithmProvidedEncryptRuleConfiguration() {
         EncryptColumnRuleConfiguration encryptColumnConfig = new 
EncryptColumnRuleConfiguration("encrypt_column", "encrypt_cipher", "", "", 
"test_encryptor");
-        EncryptTableRuleConfiguration tableConfig = new 
EncryptTableRuleConfiguration("t_encrypt", 
Collections.singletonList(encryptColumnConfig));
+        EncryptTableRuleConfiguration tableConfig = new 
EncryptTableRuleConfiguration("t_encrypt", 
Collections.singletonList(encryptColumnConfig), null);
         AlgorithmProvidedEncryptRuleConfiguration ruleConfig = new 
AlgorithmProvidedEncryptRuleConfiguration(
                 Collections.singleton(tableConfig), 
ImmutableMap.of("test_encryptor", new TestEncryptAlgorithm()), true);
         EncryptRule actual = new EncryptRule(ruleConfig);
@@ -54,7 +54,7 @@ public final class EncryptRuleTest {
     public void assertNewInstanceWithInvalidConfiguration() {
         ShardingSphereAlgorithmConfiguration encryptAlgorithmConfig = new 
ShardingSphereAlgorithmConfiguration("TEST", new Properties());
         EncryptColumnRuleConfiguration encryptColumnConfig = new 
EncryptColumnRuleConfiguration("encrypt_column", "encrypt_cipher", "", "", 
"test_encryptor");
-        EncryptTableRuleConfiguration tableConfig = new 
EncryptTableRuleConfiguration("t_encrypt", 
Collections.singletonList(encryptColumnConfig));
+        EncryptTableRuleConfiguration tableConfig = new 
EncryptTableRuleConfiguration("t_encrypt", 
Collections.singletonList(encryptColumnConfig), null);
         EncryptRuleConfiguration ruleConfig = new 
EncryptRuleConfiguration(Collections.singleton(tableConfig), 
ImmutableMap.of("invalid_encryptor", encryptAlgorithmConfig));
         new EncryptRule(ruleConfig);
     }
@@ -62,7 +62,7 @@ public final class EncryptRuleTest {
     @Test(expected = IllegalArgumentException.class)
     public void 
assertNewInstanceWithInvalidAlgorithmProvidedEncryptRuleConfiguration() {
         EncryptColumnRuleConfiguration encryptColumnConfig = new 
EncryptColumnRuleConfiguration("encrypt_column", "encrypt_cipher", "", "", 
"test_encryptor");
-        EncryptTableRuleConfiguration tableConfig = new 
EncryptTableRuleConfiguration("t_encrypt", 
Collections.singletonList(encryptColumnConfig));
+        EncryptTableRuleConfiguration tableConfig = new 
EncryptTableRuleConfiguration("t_encrypt", 
Collections.singletonList(encryptColumnConfig), null);
         AlgorithmProvidedEncryptRuleConfiguration ruleConfig = new 
AlgorithmProvidedEncryptRuleConfiguration(
                 Collections.singleton(tableConfig), 
ImmutableMap.of("invalid_encryptor", new TestEncryptAlgorithm()), true);
         new EncryptRule(ruleConfig);
@@ -147,7 +147,7 @@ public final class EncryptRuleTest {
         ShardingSphereAlgorithmConfiguration encryptAlgorithmConfig = new 
ShardingSphereAlgorithmConfiguration("QUERY_ASSISTED_TEST", new Properties());
         EncryptColumnRuleConfiguration pwdColumnConfig = new 
EncryptColumnRuleConfiguration("pwd", "pwd_cipher", "", "pwd_plain", 
"test_encryptor");
         EncryptColumnRuleConfiguration creditCardColumnConfig = new 
EncryptColumnRuleConfiguration("credit_card", "credit_card_cipher", "", 
"credit_card_plain", "test_encryptor");
-        EncryptTableRuleConfiguration tableConfig = new 
EncryptTableRuleConfiguration("t_encrypt", Arrays.asList(pwdColumnConfig, 
creditCardColumnConfig));
+        EncryptTableRuleConfiguration tableConfig = new 
EncryptTableRuleConfiguration("t_encrypt", Arrays.asList(pwdColumnConfig, 
creditCardColumnConfig), null);
         return new 
EncryptRuleConfiguration(Collections.singleton(tableConfig), 
ImmutableMap.of("test_encryptor", encryptAlgorithmConfig));
     }
 }
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptTableTest.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptTableTest.java
index 9049021..796363c 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptTableTest.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptTableTest.java
@@ -40,7 +40,7 @@ public final class EncryptTableTest {
     @Before
     public void setUp() {
         encryptTable = new EncryptTable(new 
EncryptTableRuleConfiguration("t_encrypt", 
-                Collections.singleton(new 
EncryptColumnRuleConfiguration("logicColumn", "cipherColumn", 
"assistedQueryColumn", "plainColumn", "myEncryptor"))));
+                Collections.singleton(new 
EncryptColumnRuleConfiguration("logicColumn", "cipherColumn", 
"assistedQueryColumn", "plainColumn", "myEncryptor")), null));
     }
     
     @Test
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleAlgorithmProviderConfigurationYamlSwapperTest.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleAlgorithmProviderConfigurationYamlSwapperTest.java
index 743dddf..41fb7f3 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleAlgorithmProviderConfigurationYamlSwapperTest.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleAlgorithmProviderConfigurationYamlSwapperTest.java
@@ -58,7 +58,7 @@ public final class 
EncryptRuleAlgorithmProviderConfigurationYamlSwapperTest {
     }
     
     private AlgorithmProvidedEncryptRuleConfiguration 
createAlgorithmProvidedEncryptRuleConfiguration() {
-        Collection<EncryptTableRuleConfiguration> tables = 
Collections.singletonList(new EncryptTableRuleConfiguration("tbl", 
Collections.emptyList()));
+        Collection<EncryptTableRuleConfiguration> tables = 
Collections.singletonList(new EncryptTableRuleConfiguration("tbl", 
Collections.emptyList(), null));
         Map<String, EncryptAlgorithm> encryptors = new LinkedHashMap<>();
         return new AlgorithmProvidedEncryptRuleConfiguration(tables, 
encryptors, true);
     }
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationYamlSwapperTest.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationYamlSwapperTest.java
index d139f26..7f15450 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationYamlSwapperTest.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationYamlSwapperTest.java
@@ -58,7 +58,7 @@ public final class EncryptRuleConfigurationYamlSwapperTest {
     }
     
     private EncryptRuleConfiguration createEncryptRuleConfiguration() {
-        Collection<EncryptTableRuleConfiguration> tables = 
Collections.singletonList(new EncryptTableRuleConfiguration("tbl", 
Collections.emptyList()));
+        Collection<EncryptTableRuleConfiguration> tables = 
Collections.singletonList(new EncryptTableRuleConfiguration("tbl", 
Collections.emptyList(), null));
         Map<String, ShardingSphereAlgorithmConfiguration> encryptors = 
ImmutableMap.of("myEncryptor", new ShardingSphereAlgorithmConfiguration("TEST", 
new Properties()));
         return new EncryptRuleConfiguration(tables, encryptors);
     }
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/EncryptTableRuleConfigurationYamlSwapperTest.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/EncryptTableRuleConfigurationYamlSwapperTest.java
index 16ff041..40dfa4d 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/EncryptTableRuleConfigurationYamlSwapperTest.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/EncryptTableRuleConfigurationYamlSwapperTest.java
@@ -43,7 +43,7 @@ public final class 
EncryptTableRuleConfigurationYamlSwapperTest {
                 new EncryptColumnRuleConfiguration("encrypt_column_1", 
"encrypt_cipher_1", "", "", "test_encryptor_1"), 
                 new EncryptColumnRuleConfiguration("encrypt_column_2", 
"encrypt_cipher_2", "", "", "test_encryptor_2"), 
                 new EncryptColumnRuleConfiguration("encrypt_column_3", 
"encrypt_cipher_3", "", "", "test_encryptor_3"));
-        EncryptTableRuleConfiguration encryptTableRuleConfig = new 
EncryptTableRuleConfiguration("test_table", encryptColumnRuleConfigs);
+        EncryptTableRuleConfiguration encryptTableRuleConfig = new 
EncryptTableRuleConfiguration("test_table", encryptColumnRuleConfigs, null);
         YamlEncryptTableRuleConfiguration actualYamlEncryptTableRuleConfig = 
tableRuleConfigYamlSwapper.swapToYamlConfiguration(encryptTableRuleConfig);
         assertNotNull(actualYamlEncryptTableRuleConfig);
         Map<String, YamlEncryptColumnRuleConfiguration> actualColumns = 
actualYamlEncryptTableRuleConfig.getColumns();
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverter.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverter.java
index 3dd7ceb..1d2795e 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverter.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverter.java
@@ -56,7 +56,7 @@ public final class EncryptRuleStatementConverter {
         for (EncryptColumnSegment each : ruleSegment.getColumns()) {
             
columns.add(createEncryptColumnRuleConfiguration(ruleSegment.getTableName(), 
each));
         }
-        return new EncryptTableRuleConfiguration(ruleSegment.getTableName(), 
columns);
+        return new EncryptTableRuleConfiguration(ruleSegment.getTableName(), 
columns, ruleSegment.getQueryWithCipherColumn());
     }
     
     private static EncryptColumnRuleConfiguration 
createEncryptColumnRuleConfiguration(final String tableName, final 
EncryptColumnSegment columnSegment) {
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverterTest.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverterTest.java
index 1b7dc78..9dbb98a 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverterTest.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverterTest.java
@@ -35,7 +35,7 @@ public final class EncryptRuleStatementConverterTest {
     
     @Test
     public void assertCovert() {
-        EncryptRuleConfiguration encryptRuleConfiguration = 
EncryptRuleStatementConverter.convert(Collections.singleton(new 
EncryptRuleSegment("t_encrypt", buildColumns())));
+        EncryptRuleConfiguration encryptRuleConfiguration = 
EncryptRuleStatementConverter.convert(Collections.singleton(new 
EncryptRuleSegment("t_encrypt", buildColumns(), null)));
         assertNotNull(encryptRuleConfiguration);
         
assertThat(encryptRuleConfiguration.getTables().iterator().next().getName(), 
is("t_encrypt"));
         
assertThat(encryptRuleConfiguration.getTables().iterator().next().getColumns().iterator().next().getLogicColumn(),
 is("user_id"));
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/EncryptRuleQueryResultSetTest.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/EncryptRuleQueryResultSetTest.java
index 5f3804e..3548408 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/EncryptRuleQueryResultSetTest.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/EncryptRuleQueryResultSetTest.java
@@ -57,7 +57,7 @@ public final class EncryptRuleQueryResultSetTest {
     
     private RuleConfiguration getRuleConfiguration() {
         EncryptColumnRuleConfiguration encryptColumnRuleConfig = new 
EncryptColumnRuleConfiguration("user_id", "user_cipher", null, "user_plain", 
"test");
-        EncryptTableRuleConfiguration encryptTableRuleConfig = new 
EncryptTableRuleConfiguration("t_encrypt", 
Collections.singleton(encryptColumnRuleConfig));
+        EncryptTableRuleConfiguration encryptTableRuleConfig = new 
EncryptTableRuleConfiguration("t_encrypt", 
Collections.singleton(encryptColumnRuleConfig), null);
         ShardingSphereAlgorithmConfiguration shardingSphereAlgorithmConfig = 
new ShardingSphereAlgorithmConfiguration("md5", new Properties());
         return new 
EncryptRuleConfiguration(Collections.singleton(encryptTableRuleConfig), 
Collections.singletonMap("test", shardingSphereAlgorithmConfig));
     }
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdaterTest.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdaterTest.java
index 55b5e86..d7780c7 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdaterTest.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdaterTest.java
@@ -61,12 +61,12 @@ public final class AlterEncryptRuleStatementUpdaterTest {
     
     private AlterEncryptRuleStatement createSQLStatement(final String 
encryptorName) {
         EncryptColumnSegment columnSegment = new 
EncryptColumnSegment("user_id", "user_cipher", "user_plain", "assisted_column", 
new AlgorithmSegment(encryptorName, new Properties()));
-        EncryptRuleSegment ruleSegment = new EncryptRuleSegment("t_encrypt", 
Collections.singleton(columnSegment));
+        EncryptRuleSegment ruleSegment = new EncryptRuleSegment("t_encrypt", 
Collections.singleton(columnSegment), null);
         return new 
AlterEncryptRuleStatement(Collections.singleton(ruleSegment));
     }
     
     private EncryptRuleConfiguration createCurrentRuleConfiguration() {
-        EncryptTableRuleConfiguration tableRuleConfig = new 
EncryptTableRuleConfiguration("t_encrypt", Collections.emptyList());
+        EncryptTableRuleConfiguration tableRuleConfig = new 
EncryptTableRuleConfiguration("t_encrypt", Collections.emptyList(), null);
         return new EncryptRuleConfiguration(new 
LinkedList<>(Collections.singleton(tableRuleConfig)), Collections.emptyMap());
     }
 }
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdaterTest.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdaterTest.java
index f4c53cd..fbf05bb 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdaterTest.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdaterTest.java
@@ -55,11 +55,11 @@ public final class CreateEncryptRuleStatementUpdaterTest {
     
     private CreateEncryptRuleStatement createSQLStatement(final String 
encryptorName) {
         EncryptColumnSegment columnSegment = new 
EncryptColumnSegment("user_id", "user_cipher", "user_plain", "assisted_column", 
new AlgorithmSegment(encryptorName, new Properties()));
-        EncryptRuleSegment ruleSegment = new EncryptRuleSegment("t_encrypt", 
Collections.singleton(columnSegment));
+        EncryptRuleSegment ruleSegment = new EncryptRuleSegment("t_encrypt", 
Collections.singleton(columnSegment), null);
         return new 
CreateEncryptRuleStatement(Collections.singleton(ruleSegment));
     }
     
     private EncryptRuleConfiguration getCurrentRuleConfig() {
-        return new EncryptRuleConfiguration(Collections.singleton(new 
EncryptTableRuleConfiguration("t_encrypt", Collections.emptyList())), 
Collections.emptyMap());
+        return new EncryptRuleConfiguration(Collections.singleton(new 
EncryptTableRuleConfiguration("t_encrypt", Collections.emptyList(), null)), 
Collections.emptyMap());
     }
 }
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdaterTest.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdaterTest.java
index 6ae3974..f4e65ea 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdaterTest.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdaterTest.java
@@ -80,7 +80,7 @@ public final class DropEncryptRuleStatementUpdaterTest {
     
     private EncryptRuleConfiguration createCurrentRuleConfiguration() {
         EncryptColumnRuleConfiguration columnRuleConfig = new 
EncryptColumnRuleConfiguration("user_id", "user_cipher", "", "user_plain", 
"t_encrypt_user_id_MD5");
-        EncryptTableRuleConfiguration tableRuleConfig = new 
EncryptTableRuleConfiguration("t_encrypt", 
Collections.singleton(columnRuleConfig));
+        EncryptTableRuleConfiguration tableRuleConfig = new 
EncryptTableRuleConfiguration("t_encrypt", 
Collections.singleton(columnRuleConfig), null);
         Map<String, ShardingSphereAlgorithmConfiguration> encryptors = new 
HashMap<>(1, 1);
         encryptors.put("t_encrypt_user_id_MD5", new 
ShardingSphereAlgorithmConfiguration("TEST", new Properties()));
         return new EncryptRuleConfiguration(new 
LinkedList<>(Collections.singleton(tableRuleConfig)), encryptors, true);
@@ -88,10 +88,10 @@ public final class DropEncryptRuleStatementUpdaterTest {
     
     private EncryptRuleConfiguration 
createCurrentRuleConfigurationWithMultipleTableRules() {
         EncryptColumnRuleConfiguration columnRuleConfig = new 
EncryptColumnRuleConfiguration("user_id", "user_cipher", "", "user_plain", 
"t_encrypt_user_id_MD5");
-        EncryptTableRuleConfiguration tableRuleConfig = new 
EncryptTableRuleConfiguration("t_encrypt", 
Collections.singleton(columnRuleConfig));
+        EncryptTableRuleConfiguration tableRuleConfig = new 
EncryptTableRuleConfiguration("t_encrypt", 
Collections.singleton(columnRuleConfig), null);
         Map<String, ShardingSphereAlgorithmConfiguration> encryptors = new 
HashMap<>(1, 1);
         encryptors.put("t_encrypt_user_id_MD5", new 
ShardingSphereAlgorithmConfiguration("TEST", new Properties()));
         return new EncryptRuleConfiguration(new 
LinkedList<>(Arrays.asList(tableRuleConfig, 
-                new EncryptTableRuleConfiguration("t_encrypt_another", 
Collections.singleton(columnRuleConfig)))), encryptors, true);
+                new EncryptTableRuleConfiguration("t_encrypt_another", 
Collections.singleton(columnRuleConfig), null))), encryptors, true);
     }
 }
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-parser/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptDistSQLStatementVisitor.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-parser/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptDistSQLStatementVisitor.java
index 3db9680..d55f211 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-parser/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptDistSQLStatementVisitor.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-parser/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptDistSQLStatementVisitor.java
@@ -73,7 +73,8 @@ public final class EncryptDistSQLStatementVisitor extends 
EncryptDistSQLStatemen
     
     @Override
     public ASTNode visitEncryptRuleDefinition(final 
EncryptRuleDefinitionContext ctx) {
-        return new EncryptRuleSegment(getIdentifierValue(ctx.tableName()), 
ctx.columnDefinition().stream().map(each -> (EncryptColumnSegment) 
visit(each)).collect(Collectors.toList()));
+        // todo Support table level queryWithCipherColumn configuration
+        return new EncryptRuleSegment(getIdentifierValue(ctx.tableName()), 
ctx.columnDefinition().stream().map(each -> (EncryptColumnSegment) 
visit(each)).collect(Collectors.toList()), null);
     }
     
     @Override
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-statement/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/segment/EncryptRuleSegment.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-statement/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/segment/EncryptRuleSegment.java
index bbbcac4..41e84a3 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-statement/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/segment/EncryptRuleSegment.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-statement/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/segment/EncryptRuleSegment.java
@@ -33,4 +33,6 @@ public final class EncryptRuleSegment implements ASTNode {
     private final String tableName;
     
     private final Collection<EncryptColumnSegment> columns;
+    
+    private final Boolean queryWithCipherColumn;
 }
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/java/org/apache/shardingsphere/encrypt/spring/boot/EncryptSpringBootStarterTest.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/java/org/apache/shardingsphere/encrypt/spring/boot/EncryptSpringBootStarterTest.java
index 609dd0a..4583ee2 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/java/org/apache/shardingsphere/encrypt/spring/boot/EncryptSpringBootStarterTest.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/java/org/apache/shardingsphere/encrypt/spring/boot/EncryptSpringBootStarterTest.java
@@ -73,6 +73,7 @@ public class EncryptSpringBootStarterTest {
     private void assertEncryptTable(final EncryptTableRuleConfiguration 
tableRuleConfig) {
         assertThat(tableRuleConfig.getName(), is("t_order"));
         assertThat(tableRuleConfig.getColumns().size(), is(2));
+        assertThat(tableRuleConfig.getQueryWithCipherColumn(), is(false));
         Iterator<EncryptColumnRuleConfiguration> columnRuleConfigs = 
tableRuleConfig.getColumns().iterator();
         assertEncryptColumn2(columnRuleConfigs.next());
         assertEncryptColumn1(columnRuleConfigs.next());
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/resources/application-encrypt.properties
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/resources/application-encrypt.properties
index 1932702..a82ee0a 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/resources/application-encrypt.properties
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/resources/application-encrypt.properties
@@ -20,6 +20,7 @@ 
spring.shardingsphere.rules.encrypt.encryptors.aesEncryptor.props.aes-key-value=
 
 spring.shardingsphere.rules.encrypt.encryptors.md5Encryptor.type=MD5
 
+spring.shardingsphere.rules.encrypt.tables.t_order.query-with-cipher-column=false
 
spring.shardingsphere.rules.encrypt.tables.t_order.columns.pwd.cipher-column=pwd_cipher
 
spring.shardingsphere.rules.encrypt.tables.t_order.columns.pwd.plain-column=pwd_plain
 
spring.shardingsphere.rules.encrypt.tables.t_order.columns.pwd.encryptor-name=aesEncryptor
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/parser/EncryptRuleBeanDefinitionParser.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/parser/EncryptRuleBeanDefinitionParser.java
index 66cd6f4..c1261bb 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/parser/EncryptRuleBeanDefinitionParser.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/parser/EncryptRuleBeanDefinitionParser.java
@@ -63,6 +63,7 @@ public final class EncryptRuleBeanDefinitionParser extends 
AbstractBeanDefinitio
         BeanDefinitionBuilder factory = 
BeanDefinitionBuilder.rootBeanDefinition(EncryptTableRuleConfiguration.class);
         
factory.addConstructorArgValue(element.getAttribute(BeanDefinitionParserDelegate.NAME_ATTRIBUTE));
         
factory.addConstructorArgValue(parseEncryptColumnRuleConfigurations(element));
+        
factory.addConstructorArgValue(element.getAttribute(EncryptRuleBeanDefinitionTag.QUERY_WITH_CIPHER_COLUMN));
         return factory.getBeanDefinition();
     }
     
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/resources/META-INF/namespace/encrypt.xsd
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/resources/META-INF/namespace/encrypt.xsd
index 02a0e3f..36418c7 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/resources/META-INF/namespace/encrypt.xsd
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/resources/META-INF/namespace/encrypt.xsd
@@ -39,6 +39,7 @@
                 <xsd:element ref="column" maxOccurs="unbounded" />
             </xsd:sequence>
             <xsd:attribute name="name" type="xsd:string" use="required" />
+            <xsd:attribute name="query-with-cipher-column" type="xsd:boolean" 
/>
         </xsd:complexType>
     </xsd:element>
      <xsd:element name="column">
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/test/java/org/apache/shardingsphere/encrypt/spring/namespace/EncryptSpringNamespaceTest.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/test/java/org/apache/shardingsphere/encrypt/spring/namespace/EncryptSpringNamespaceTest.java
index bd15a0d..0045a76 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/test/java/org/apache/shardingsphere/encrypt/spring/namespace/EncryptSpringNamespaceTest.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/test/java/org/apache/shardingsphere/encrypt/spring/namespace/EncryptSpringNamespaceTest.java
@@ -74,6 +74,7 @@ public final class EncryptSpringNamespaceTest extends 
AbstractJUnit4SpringContex
     
     private void assertEncryptTable(final EncryptTableRuleConfiguration 
tableRuleConfig) {
         assertThat(tableRuleConfig.getName(), is("t_order"));
+        assertThat(tableRuleConfig.getQueryWithCipherColumn(), is(false));
         assertThat(tableRuleConfig.getColumns().size(), is(2));
         Iterator<EncryptColumnRuleConfiguration> columnRuleConfigs = 
tableRuleConfig.getColumns().iterator();
         assertEncryptColumn1(columnRuleConfigs.next());
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/test/resources/META-INF/spring/encrypt-application-context.xml
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/test/resources/META-INF/spring/encrypt-application-context.xml
index ac4c2f0..11e47e0 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/test/resources/META-INF/spring/encrypt-application-context.xml
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/test/resources/META-INF/spring/encrypt-application-context.xml
@@ -37,7 +37,7 @@
     <encrypt:encrypt-algorithm id="md5Encryptor" type="MD5" />
     
     <encrypt:rule id="encryptRule">
-        <encrypt:table name="t_order">
+        <encrypt:table name="t_order" query-with-cipher-column="false">
             <encrypt:column logic-column="pwd" cipher-column="pwd_cipher" 
encrypt-algorithm-ref="aesEncryptor" />
             <encrypt:column logic-column="credit_card" 
cipher-column="credit_card_cipher" 
assisted-query-column="credit_card_assisted_query" 
plain-column="credit_card_plain" encrypt-algorithm-ref="md5Encryptor" />
         </encrypt:table>

Reply via email to