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 c1dff3328d2 Split EncryptOrderByItemTokenGenerator into order by and 
group by token generator and add unsupported check for encrypt column order by 
(#28225)
c1dff3328d2 is described below

commit c1dff3328d25ba71c3db0205c4ab6c3f8fee69e6
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Wed Aug 23 08:55:01 2023 +0800

    Split EncryptOrderByItemTokenGenerator into order by and group by token 
generator and add unsupported check for encrypt column order by (#28225)
---
 .../rewrite/token/EncryptTokenGenerateBuilder.java |  2 +
 ....java => EncryptGroupByItemTokenGenerator.java} | 24 +++++-------
 .../EncryptOrderByItemTokenGenerator.java          | 31 +++------------
 ...a => EncryptGroupByItemTokenGeneratorTest.java} |  7 ++--
 .../EncryptOrderByItemTokenGeneratorTest.java      |  6 +--
 .../dml/select/select-distinct.xml                 | 24 ++++++++++++
 .../dml/select/select-order-by.xml                 | 45 ----------------------
 .../dml/select/select-subquery.xml                 |  6 +--
 8 files changed, 50 insertions(+), 95 deletions(-)

diff --git 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/EncryptTokenGenerateBuilder.java
 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/EncryptTokenGenerateBuilder.java
index d88307b641e..a5eea848e1a 100644
--- 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/EncryptTokenGenerateBuilder.java
+++ 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/EncryptTokenGenerateBuilder.java
@@ -27,6 +27,7 @@ import 
org.apache.shardingsphere.encrypt.rewrite.token.generator.EncryptAlterTab
 import 
org.apache.shardingsphere.encrypt.rewrite.token.generator.EncryptAssignmentTokenGenerator;
 import 
org.apache.shardingsphere.encrypt.rewrite.token.generator.EncryptCreateTableTokenGenerator;
 import 
org.apache.shardingsphere.encrypt.rewrite.token.generator.EncryptForUseDefaultInsertColumnsTokenGenerator;
+import 
org.apache.shardingsphere.encrypt.rewrite.token.generator.EncryptGroupByItemTokenGenerator;
 import 
org.apache.shardingsphere.encrypt.rewrite.token.generator.EncryptIndexColumnTokenGenerator;
 import 
org.apache.shardingsphere.encrypt.rewrite.token.generator.EncryptOrderByItemTokenGenerator;
 import 
org.apache.shardingsphere.encrypt.rewrite.token.generator.EncryptPredicateColumnTokenGenerator;
@@ -73,6 +74,7 @@ public final class EncryptTokenGenerateBuilder implements 
SQLTokenGeneratorBuild
         addSQLTokenGenerator(result, new EncryptCreateTableTokenGenerator());
         addSQLTokenGenerator(result, new EncryptAlterTableTokenGenerator());
         addSQLTokenGenerator(result, new EncryptOrderByItemTokenGenerator());
+        addSQLTokenGenerator(result, new EncryptGroupByItemTokenGenerator());
         addSQLTokenGenerator(result, new EncryptIndexColumnTokenGenerator());
         return result;
     }
diff --git 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGenerator.java
 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptGroupByItemTokenGenerator.java
similarity index 88%
copy from 
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGenerator.java
copy to 
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptGroupByItemTokenGenerator.java
index 3d72c17c319..7a5b93253eb 100644
--- 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGenerator.java
+++ 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptGroupByItemTokenGenerator.java
@@ -48,10 +48,10 @@ import java.util.Map;
 import java.util.Optional;
 
 /**
- * Order by item token generator for encrypt.
+ * Group by item token generator for encrypt.
  */
 @Setter
-public final class EncryptOrderByItemTokenGenerator implements 
CollectionSQLTokenGenerator<SQLStatementContext>, SchemaMetaDataAware, 
EncryptRuleAware, DatabaseTypeAware {
+public final class EncryptGroupByItemTokenGenerator implements 
CollectionSQLTokenGenerator<SQLStatementContext>, SchemaMetaDataAware, 
EncryptRuleAware, DatabaseTypeAware {
     
     private String databaseName;
     
@@ -63,7 +63,7 @@ public final class EncryptOrderByItemTokenGenerator 
implements CollectionSQLToke
     
     @Override
     public boolean isGenerateSQLToken(final SQLStatementContext 
sqlStatementContext) {
-        return sqlStatementContext instanceof SelectStatementContext && 
containsOrderByItem(sqlStatementContext);
+        return sqlStatementContext instanceof SelectStatementContext && 
containsGroupByItem(sqlStatementContext);
     }
     
     @Override
@@ -71,7 +71,7 @@ public final class EncryptOrderByItemTokenGenerator 
implements CollectionSQLToke
         Collection<SQLToken> result = new LinkedHashSet<>();
         String defaultSchema = new 
DatabaseTypeRegistry(sqlStatementContext.getDatabaseType()).getDefaultSchemaName(databaseName);
         ShardingSphereSchema schema = 
sqlStatementContext.getTablesContext().getSchemaName().map(schemas::get).orElseGet(()
 -> schemas.get(defaultSchema));
-        for (OrderByItem each : getOrderByItems(sqlStatementContext)) {
+        for (OrderByItem each : getGroupByItems(sqlStatementContext)) {
             if (each.getSegment() instanceof ColumnOrderByItemSegment) {
                 ColumnSegment columnSegment = ((ColumnOrderByItemSegment) 
each.getSegment()).getColumn();
                 Map<String, String> columnTableNames = 
sqlStatementContext.getTablesContext().findTableNamesByColumnSegment(Collections.singleton(columnSegment),
 schema);
@@ -101,32 +101,28 @@ public final class EncryptOrderByItemTokenGenerator 
implements CollectionSQLToke
         return result;
     }
     
-    private Collection<OrderByItem> getOrderByItems(final SQLStatementContext 
sqlStatementContext) {
+    private Collection<OrderByItem> getGroupByItems(final SQLStatementContext 
sqlStatementContext) {
         if (!(sqlStatementContext instanceof SelectStatementContext)) {
             return Collections.emptyList();
         }
-        Collection<OrderByItem> result = new LinkedList<>();
         SelectStatementContext statementContext = (SelectStatementContext) 
sqlStatementContext;
-        if (!statementContext.getOrderByContext().isGenerated()) {
-            result.addAll(statementContext.getOrderByContext().getItems());
-        }
-        result.addAll(statementContext.getGroupByContext().getItems());
+        Collection<OrderByItem> result = new 
LinkedList<>(statementContext.getGroupByContext().getItems());
         for (SelectStatementContext each : 
statementContext.getSubqueryContexts().values()) {
-            result.addAll(getOrderByItems(each));
+            result.addAll(getGroupByItems(each));
         }
         return result;
     }
     
-    private boolean containsOrderByItem(final SQLStatementContext 
sqlStatementContext) {
+    private boolean containsGroupByItem(final SQLStatementContext 
sqlStatementContext) {
         if (!(sqlStatementContext instanceof SelectStatementContext)) {
             return false;
         }
         SelectStatementContext statementContext = (SelectStatementContext) 
sqlStatementContext;
-        if (!statementContext.getOrderByContext().getItems().isEmpty() && 
!statementContext.getOrderByContext().isGenerated() || 
!statementContext.getGroupByContext().getItems().isEmpty()) {
+        if (!statementContext.getGroupByContext().getItems().isEmpty()) {
             return true;
         }
         for (SelectStatementContext each : 
statementContext.getSubqueryContexts().values()) {
-            if (containsOrderByItem(each)) {
+            if (containsGroupByItem(each)) {
                 return true;
             }
         }
diff --git 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGenerator.java
 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGenerator.java
index 3d72c17c319..4e1acb3a29f 100644
--- 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGenerator.java
+++ 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGenerator.java
@@ -18,19 +18,15 @@
 package org.apache.shardingsphere.encrypt.rewrite.token.generator;
 
 import lombok.Setter;
-import org.apache.shardingsphere.encrypt.rewrite.aware.DatabaseTypeAware;
+import 
org.apache.shardingsphere.encrypt.exception.syntax.UnsupportedEncryptSQLException;
 import org.apache.shardingsphere.encrypt.rewrite.aware.EncryptRuleAware;
 import org.apache.shardingsphere.encrypt.rule.EncryptRule;
 import org.apache.shardingsphere.encrypt.rule.EncryptTable;
-import org.apache.shardingsphere.encrypt.rule.column.EncryptColumn;
 import 
org.apache.shardingsphere.infra.binder.context.segment.select.orderby.OrderByItem;
-import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.Projection;
-import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl.ColumnProjection;
 import 
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
 import 
org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
-import 
org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
+import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
 import 
org.apache.shardingsphere.infra.rewrite.sql.token.generator.CollectionSQLTokenGenerator;
 import 
org.apache.shardingsphere.infra.rewrite.sql.token.generator.aware.SchemaMetaDataAware;
@@ -38,7 +34,6 @@ import 
org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
 import 
org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.SubstitutableColumnNameToken;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.ColumnOrderByItemSegment;
-import 
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
 
 import java.util.Collection;
 import java.util.Collections;
@@ -51,7 +46,7 @@ import java.util.Optional;
  * Order by item token generator for encrypt.
  */
 @Setter
-public final class EncryptOrderByItemTokenGenerator implements 
CollectionSQLTokenGenerator<SQLStatementContext>, SchemaMetaDataAware, 
EncryptRuleAware, DatabaseTypeAware {
+public final class EncryptOrderByItemTokenGenerator implements 
CollectionSQLTokenGenerator<SQLStatementContext>, SchemaMetaDataAware, 
EncryptRuleAware {
     
     private String databaseName;
     
@@ -59,8 +54,6 @@ public final class EncryptOrderByItemTokenGenerator 
implements CollectionSQLToke
     
     private EncryptRule encryptRule;
     
-    private DatabaseType databaseType;
-    
     @Override
     public boolean isGenerateSQLToken(final SQLStatementContext 
sqlStatementContext) {
         return sqlStatementContext instanceof SelectStatementContext && 
containsOrderByItem(sqlStatementContext);
@@ -87,16 +80,7 @@ public final class EncryptOrderByItemTokenGenerator 
implements CollectionSQLToke
             String tableName = 
columnTableNames.getOrDefault(each.getExpression(), "");
             Optional<EncryptTable> encryptTable = 
encryptRule.findEncryptTable(tableName);
             String columnName = each.getIdentifier().getValue();
-            if (!encryptTable.isPresent() || 
!encryptTable.get().isEncryptColumn(columnName)) {
-                continue;
-            }
-            int startIndex = each.getOwner().isPresent() ? 
each.getOwner().get().getStopIndex() + 2 : each.getStartIndex();
-            int stopIndex = each.getStopIndex();
-            EncryptColumn encryptColumn = 
encryptTable.get().getEncryptColumn(columnName);
-            SubstitutableColumnNameToken encryptColumnNameToken = 
encryptColumn.getAssistedQuery()
-                    .map(optional -> new 
SubstitutableColumnNameToken(startIndex, stopIndex, 
createColumnProjections(optional.getName(), 
each.getIdentifier().getQuoteCharacter())))
-                    .orElseGet(() -> new 
SubstitutableColumnNameToken(startIndex, stopIndex, 
createColumnProjections(encryptColumn.getCipher().getName(), 
each.getIdentifier().getQuoteCharacter())));
-            result.add(encryptColumnNameToken);
+            ShardingSpherePreconditions.checkState(!encryptTable.isPresent() 
|| !encryptTable.get().isEncryptColumn(columnName), () -> new 
UnsupportedEncryptSQLException("ORDER BY"));
         }
         return result;
     }
@@ -110,7 +94,6 @@ public final class EncryptOrderByItemTokenGenerator 
implements CollectionSQLToke
         if (!statementContext.getOrderByContext().isGenerated()) {
             result.addAll(statementContext.getOrderByContext().getItems());
         }
-        result.addAll(statementContext.getGroupByContext().getItems());
         for (SelectStatementContext each : 
statementContext.getSubqueryContexts().values()) {
             result.addAll(getOrderByItems(each));
         }
@@ -122,7 +105,7 @@ public final class EncryptOrderByItemTokenGenerator 
implements CollectionSQLToke
             return false;
         }
         SelectStatementContext statementContext = (SelectStatementContext) 
sqlStatementContext;
-        if (!statementContext.getOrderByContext().getItems().isEmpty() && 
!statementContext.getOrderByContext().isGenerated() || 
!statementContext.getGroupByContext().getItems().isEmpty()) {
+        if (!statementContext.getOrderByContext().getItems().isEmpty() && 
!statementContext.getOrderByContext().isGenerated()) {
             return true;
         }
         for (SelectStatementContext each : 
statementContext.getSubqueryContexts().values()) {
@@ -132,8 +115,4 @@ public final class EncryptOrderByItemTokenGenerator 
implements CollectionSQLToke
         }
         return false;
     }
-    
-    private Collection<Projection> createColumnProjections(final String 
columnName, final QuoteCharacter quoteCharacter) {
-        return Collections.singleton(new ColumnProjection(null, new 
IdentifierValue(columnName, quoteCharacter), null, databaseType));
-    }
 }
diff --git 
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGeneratorTest.java
 
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptGroupByItemTokenGeneratorTest.java
similarity index 95%
copy from 
features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGeneratorTest.java
copy to 
features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptGroupByItemTokenGeneratorTest.java
index 451fdea27d0..08ce51aa100 100644
--- 
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGeneratorTest.java
+++ 
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptGroupByItemTokenGeneratorTest.java
@@ -47,9 +47,9 @@ import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-class EncryptOrderByItemTokenGeneratorTest {
+class EncryptGroupByItemTokenGeneratorTest {
     
-    private final EncryptOrderByItemTokenGenerator generator = new 
EncryptOrderByItemTokenGenerator();
+    private final EncryptGroupByItemTokenGenerator generator = new 
EncryptGroupByItemTokenGenerator();
     
     private final DatabaseType databaseType = 
TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
     
@@ -85,8 +85,7 @@ class EncryptOrderByItemTokenGeneratorTest {
         when(result.getDatabaseType()).thenReturn(databaseType);
         ColumnOrderByItemSegment columnOrderByItemSegment = new 
ColumnOrderByItemSegment(columnSegment, OrderDirection.ASC, 
NullsOrderType.FIRST);
         OrderByItem orderByItem = new OrderByItem(columnOrderByItemSegment);
-        
when(result.getOrderByContext().getItems()).thenReturn(Collections.singleton(orderByItem));
-        
when(result.getGroupByContext().getItems()).thenReturn(Collections.emptyList());
+        
when(result.getGroupByContext().getItems()).thenReturn(Collections.singleton(orderByItem));
         
when(result.getSubqueryContexts().values()).thenReturn(Collections.emptyList());
         when(result.getTablesContext()).thenReturn(new 
TablesContext(Collections.singleton(simpleTableSegment), databaseType));
         return result;
diff --git 
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGeneratorTest.java
 
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGeneratorTest.java
index 451fdea27d0..387b52f4dc3 100644
--- 
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGeneratorTest.java
+++ 
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGeneratorTest.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.encrypt.rewrite.token.generator;
 
+import 
org.apache.shardingsphere.encrypt.exception.syntax.UnsupportedEncryptSQLException;
 import org.apache.shardingsphere.encrypt.rule.EncryptRule;
 import org.apache.shardingsphere.encrypt.rule.EncryptTable;
 import org.apache.shardingsphere.encrypt.rule.column.EncryptColumn;
@@ -41,8 +42,7 @@ import org.junit.jupiter.api.Test;
 import java.util.Collections;
 import java.util.Optional;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -73,7 +73,7 @@ class EncryptOrderByItemTokenGeneratorTest {
     
     @Test
     void assertGenerateSQLTokens() {
-        
assertThat(generator.generateSQLTokens(buildSelectStatementContext()).size(), 
is(1));
+        assertThrows(UnsupportedEncryptSQLException.class, () -> 
generator.generateSQLTokens(buildSelectStatementContext()));
     }
     
     private SelectStatementContext buildSelectStatementContext() {
diff --git 
a/test/it/rewriter/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select-distinct.xml
 
b/test/it/rewriter/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select-distinct.xml
new file mode 100644
index 00000000000..793b33f56a1
--- /dev/null
+++ 
b/test/it/rewriter/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select-distinct.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<rewrite-assertions yaml-rule="scenario/encrypt/config/query-with-cipher.yaml">
+    <rewrite-assertion 
id="select_distinct_cipher_field_without_order_by_cipher" db-types="MySQL">
+        <input sql="SELECT distinct amount FROM t_account" />
+        <output sql="SELECT distinct cipher_amount AS amount FROM t_account" />
+    </rewrite-assertion>
+</rewrite-assertions>
diff --git 
a/test/it/rewriter/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select-order-by.xml
 
b/test/it/rewriter/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select-order-by.xml
deleted file mode 100644
index 6730842c676..00000000000
--- 
a/test/it/rewriter/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select-order-by.xml
+++ /dev/null
@@ -1,45 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-  ~ 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.
-  -->
-
-<rewrite-assertions yaml-rule="scenario/encrypt/config/query-with-cipher.yaml">
-    <rewrite-assertion id="select_for_parameters_with_order_by_assisted" 
db-types="MySQL">
-        <input sql="SELECT account_id, password, amount AS a, status AS s FROM 
t_account WHERE account_id = ? AND password = ? AND password like ? AND amount 
= ? AND status = ? order by password desc" parameters="1, aaa, aaa, 1000, OK" />
-        <output sql="SELECT account_id, cipher_password AS password, 
cipher_amount AS a, status AS s FROM t_account WHERE account_id = ? AND 
assisted_query_password = ? AND like_query_password like ? AND cipher_amount = 
? AND status = ? order by assisted_query_password desc" parameters="1, 
assisted_query_aaa, like_query_aaa, encrypt_1000, OK" />
-    </rewrite-assertion>
-    
-    <rewrite-assertion id="select_for_literals_with_order_by_assisted" 
db-types="MySQL">
-        <input sql="SELECT account_id, password, amount AS a, status AS s FROM 
t_account WHERE account_id = 1 AND password = 'aaa' AND password like 'aaa' AND 
amount = '1000' AND status = 'OK' order by password desc" />
-        <output sql="SELECT account_id, cipher_password AS password, 
cipher_amount AS a, status AS s FROM t_account WHERE account_id = 1 AND 
assisted_query_password = 'assisted_query_aaa' AND like_query_password like 
'like_query_aaa' AND cipher_amount = 'encrypt_1000' AND status = 'OK' order by 
assisted_query_password desc" />
-    </rewrite-assertion>
-    
-    <rewrite-assertion id="select_for_parameters_with_order_by_cipher" 
db-types="MySQL">
-        <input sql="SELECT account_id, password, amount AS a, status AS s FROM 
t_account WHERE account_id = ? AND password = ? AND password like ? AND amount 
= ? AND status = ? order by amount desc" parameters="1, aaa, aaa, 1000, OK" />
-        <output sql="SELECT account_id, cipher_password AS password, 
cipher_amount AS a, status AS s FROM t_account WHERE account_id = ? AND 
assisted_query_password = ? AND like_query_password like ? AND cipher_amount = 
? AND status = ? order by cipher_amount desc" parameters="1, 
assisted_query_aaa, like_query_aaa, encrypt_1000, OK" />
-    </rewrite-assertion>
-    
-    <rewrite-assertion id="select_for_literals_with_order_by_cipher" 
db-types="MySQL">
-        <input sql="SELECT account_id, password, amount AS a, status AS s FROM 
t_account WHERE account_id = 1 AND password = 'aaa' AND password like 'aaa' AND 
amount = '1000' AND status = 'OK' order by amount desc" />
-        <output sql="SELECT account_id, cipher_password AS password, 
cipher_amount AS a, status AS s FROM t_account WHERE account_id = 1 AND 
assisted_query_password = 'assisted_query_aaa' AND like_query_password like 
'like_query_aaa' AND cipher_amount = 'encrypt_1000' AND status = 'OK' order by 
cipher_amount desc" />
-    </rewrite-assertion>
-
-    <rewrite-assertion 
id="select_distinct_cipher_field_without_order_by_cipher" db-types="MySQL">
-        <input sql="SELECT distinct amount FROM t_account" />
-        <output sql="SELECT distinct cipher_amount AS amount FROM t_account" />
-    </rewrite-assertion>
-
-</rewrite-assertions>
diff --git 
a/test/it/rewriter/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select-subquery.xml
 
b/test/it/rewriter/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select-subquery.xml
index 45dd5f6b56a..6d9e381ba95 100644
--- 
a/test/it/rewriter/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select-subquery.xml
+++ 
b/test/it/rewriter/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select-subquery.xml
@@ -97,8 +97,8 @@
         <output sql="SELECT out_table.cipher_amount AS amount FROM t_account 
out_table WHERE EXISTS (SELECT inner_table.cipher_amount AS amount FROM 
t_account inner_table)" />
     </rewrite-assertion>
 
-    <rewrite-assertion id="select_sub_query_with_order_by" db-types="MySQL">
-        <input sql="SELECT COUNT(1) AS cnt FROM (SELECT a.amount FROM 
t_account a ORDER BY a.amount DESC ) AS tmp" />
-        <output sql="SELECT COUNT(1) AS cnt FROM (SELECT a.cipher_amount AS 
amount FROM t_account a ORDER BY a.cipher_amount DESC ) AS tmp" />
+    <rewrite-assertion id="select_sub_query_with_group_by" db-types="MySQL">
+        <input sql="SELECT COUNT(1) AS cnt FROM (SELECT a.amount FROM 
t_account a GROUP BY a.amount DESC ) AS tmp" />
+        <output sql="SELECT COUNT(1) AS cnt FROM (SELECT a.cipher_amount AS 
amount FROM t_account a GROUP BY a.cipher_amount DESC ) AS tmp" />
     </rewrite-assertion>
 </rewrite-assertions>

Reply via email to