This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 bd5fe0d Fix encrypt exists sub query. (#14459)
bd5fe0d is described below
commit bd5fe0dacd47359f2300d3c884e5503c8c9c68cc
Author: tuichenchuxin <[email protected]>
AuthorDate: Fri Dec 31 17:42:32 2021 +0800
Fix encrypt exists sub query. (#14459)
---
.../sql/parser/sql/common/util/SubqueryExtractUtil.java | 7 +++++++
.../scenario/encrypt/case/select_for_query_with_cipher.xml | 5 +++++
.../src/test/resources/scenario/sharding/case/select.xml | 2 +-
3 files changed, 13 insertions(+), 1 deletion(-)
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SubqueryExtractUtil.java
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SubqueryExtractUtil.java
index 614ee0d..20014f3 100644
---
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SubqueryExtractUtil.java
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SubqueryExtractUtil.java
@@ -22,6 +22,7 @@ import lombok.NoArgsConstructor;
import org.apache.shardingsphere.sql.parser.sql.common.constant.SubqueryType;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BetweenExpression;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExistsSubqueryExpression;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.InExpression;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ListExpression;
@@ -104,6 +105,12 @@ public final class SubqueryExtractUtil {
result.add(subquery);
result.addAll(getSubquerySegments(subquery.getSelect()));
}
+ if (expressionSegment instanceof ExistsSubqueryExpression) {
+ SubquerySegment subquery = ((ExistsSubqueryExpression)
expressionSegment).getSubquery();
+ subquery.setSubqueryType(SubqueryType.PREDICATE_SUBQUERY);
+ result.add(subquery);
+ result.addAll(getSubquerySegments(subquery.getSelect()));
+ }
if (expressionSegment instanceof ListExpression) {
for (ExpressionSegment each : ((ListExpression)
expressionSegment).getItems()) {
result.addAll(getSubquerySegmentsFromExpression(each));
diff --git
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/select_for_query_with_cipher.xml
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/select_for_query_with_cipher.xml
index 38722fc..4f14233 100644
---
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/select_for_query_with_cipher.xml
+++
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/select_for_query_with_cipher.xml
@@ -178,4 +178,9 @@
<input sql="SELECT a.account_id, a.password, a.amount AS a, a.status
AS s FROM t_account_detail AS a WHERE a.account_id = 1 AND a.password = 'aaa'
AND a.amount = '1000' AND a.status = 'OK'" />
<output sql="SELECT a.account_id, a.plain_password AS password,
a.plain_amount AS a, a.status AS s FROM t_account_detail AS a WHERE
a.account_id = 1 AND a.plain_password = 'aaa' AND a.plain_amount = '1000' AND
a.status = 'OK'" />
</rewrite-assertion>
+
+ <rewrite-assertion id="select_with_exists_sub_query" db-types="MySQL">
+ <input sql="SELECT out_table.amount FROM t_account out_table WHERE
EXISTS (SELECT inner_table.amount FROM t_account inner_table)" />
+ <output sql="SELECT out_table.cipher_amount AS amount FROM t_account
out_table WHERE EXISTS (SELECT inner_table.cipher_amount FROM t_account
inner_table)" />
+ </rewrite-assertion>
</rewrite-assertions>
diff --git
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/select.xml
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/select.xml
index aab31fa..a66c8ae 100644
---
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/select.xml
+++
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/select.xml
@@ -39,7 +39,7 @@
<rewrite-assertion id="select_with_not_exists" db-types="MySQL">
<input sql="SELECT * FROM t_account a WHERE not exists (select * from
t_account_detail where a.account_id=account_id and account_id=1000) and
account_id = 100" />
- <output sql="SELECT * FROM t_account_0 a WHERE not exists (select *
from t_account_detail_0 where a.account_id=account_id and account_id=1000) and
account_id = 100" />
+ <output sql="SELECT * FROM t_account a WHERE not exists (select * from
t_account_detail where a.account_id=account_id and account_id=1000) and
account_id = 100" />
</rewrite-assertion>
<rewrite-assertion id="select_with_sum_fun">