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 90231b24e38 Minor refactor for EncryptPredicateColumnTokenGenerator 
(#34879)
90231b24e38 is described below

commit 90231b24e38a407db683cbd0b01f4f7984828c3a
Author: Zhengqiang Duan <duanzhengqi...@apache.org>
AuthorDate: Wed Mar 5 11:22:02 2025 +0800

    Minor refactor for EncryptPredicateColumnTokenGenerator (#34879)
    
    Co-authored-by: shardingsphere <d...@shardingsphere.apache.org>
---
 .../predicate/EncryptPredicateColumnTokenGenerator.java        |  8 +++++---
 .../predicate/EncryptPredicateColumnTokenGeneratorTest.java    |  2 +-
 .../case/query-with-cipher/dml/select/select-subquery.xml      | 10 +++++-----
 3 files changed, 11 insertions(+), 9 deletions(-)

diff --git 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateColumnTokenGenerator.java
 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateColumnTokenGenerator.java
index f56366d4163..99fc28bd12f 100644
--- 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateColumnTokenGenerator.java
+++ 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateColumnTokenGenerator.java
@@ -32,7 +32,7 @@ import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.
 import 
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
 import 
org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
 import org.apache.shardingsphere.infra.binder.context.type.WhereAvailable;
-import 
org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData;
+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.rewrite.sql.token.common.generator.CollectionSQLTokenGenerator;
@@ -131,8 +131,10 @@ public final class EncryptPredicateColumnTokenGenerator 
implements CollectionSQL
         String columnName = TableSourceType.TEMPORARY_TABLE == 
columnSegment.getColumnBoundInfo().getTableSourceType()
                 ? 
derivedColumnSuffix.getDerivedColumnName(columnSegment.getIdentifier().getValue(),
 databaseType)
                 : actualColumnName;
-        DialectDatabaseMetaData dialectDatabaseMetaData = new 
DatabaseTypeRegistry(databaseType).getDialectDatabaseMetaData();
-        ColumnProjection columnProjection = new ColumnProjection(null, new 
IdentifierValue(columnName, dialectDatabaseMetaData.getQuoteCharacter()), null, 
databaseType);
+        QuoteCharacter quoteCharacter = TableSourceType.TEMPORARY_TABLE == 
columnSegment.getColumnBoundInfo().getTableSourceType()
+                ? columnSegment.getIdentifier().getQuoteCharacter()
+                : new 
DatabaseTypeRegistry(databaseType).getDialectDatabaseMetaData().getQuoteCharacter();
+        ColumnProjection columnProjection = new ColumnProjection(null, new 
IdentifierValue(columnName, quoteCharacter), null, databaseType);
         return Collections.singleton(columnProjection);
     }
 }
diff --git 
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateColumnTokenGeneratorTest.java
 
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateColumnTokenGeneratorTest.java
index 76162821368..0bedf22be23 100644
--- 
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateColumnTokenGeneratorTest.java
+++ 
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateColumnTokenGeneratorTest.java
@@ -47,6 +47,6 @@ class EncryptPredicateColumnTokenGeneratorTest {
     void assertGenerateSQLTokenFromGenerateNewSQLToken() {
         Collection<SQLToken> substitutableColumnNameTokens = 
generator.generateSQLTokens(EncryptGeneratorFixtureBuilder.createUpdateStatementContext());
         assertThat(substitutableColumnNameTokens.size(), is(1));
-        assertThat(((SubstitutableColumnNameToken) 
substitutableColumnNameTokens.iterator().next()).toString(null), 
is("`pwd_ASSISTED`"));
+        assertThat(((SubstitutableColumnNameToken) 
substitutableColumnNameTokens.iterator().next()).toString(null), 
is("pwd_ASSISTED"));
     }
 }
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 7c2ed460cd2..cdbedbb1e04 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
@@ -24,12 +24,12 @@
 
     <rewrite-assertion id="select_not_nested_subquery_in_table_segment" 
db-types="MySQL">
         <input sql="SELECT u.amount, u.password, o.certificate_number FROM 
(SELECT certificate_number FROM t_account) o, t_account u WHERE 
o.certificate_number=u.certificate_number AND u.password=?" parameters="1" />
-        <output sql="SELECT u.cipher_amount AS amount, u.cipher_password AS 
password, o.certificate_number_CIPHER AS certificate_number FROM (SELECT 
cipher_certificate_number AS certificate_number_CIPHER, 
assisted_query_certificate_number AS certificate_number_ASSISTED, 
like_query_certificate_number AS certificate_number_LIKE FROM t_account) o, 
t_account u WHERE 
o.`certificate_number_ASSISTED`=u.`assisted_query_certificate_number` AND 
u.`assisted_query_password`=?" parameters="assisted_q [...]
+        <output sql="SELECT u.cipher_amount AS amount, u.cipher_password AS 
password, o.certificate_number_CIPHER AS certificate_number FROM (SELECT 
cipher_certificate_number AS certificate_number_CIPHER, 
assisted_query_certificate_number AS certificate_number_ASSISTED, 
like_query_certificate_number AS certificate_number_LIKE FROM t_account) o, 
t_account u WHERE 
o.certificate_number_ASSISTED=u.`assisted_query_certificate_number` AND 
u.`assisted_query_password`=?" parameters="assisted_que [...]
     </rewrite-assertion>
 
     <rewrite-assertion id="select_not_nested_subquery_in_table_segment_refed" 
db-types="MySQL">
         <input sql="SELECT u.amount, u.password, o.certificate_number FROM 
(SELECT certificate_number FROM t_account_bak) o, t_account u WHERE 
o.certificate_number=u.certificate_number AND u.password=?" parameters="1" />
-        <output sql="SELECT u.cipher_amount AS amount, u.cipher_password AS 
password, o.certificate_number_CIPHER AS certificate_number FROM (SELECT 
cipher_certificate_number AS certificate_number_CIPHER, 
assisted_query_certificate_number AS certificate_number_ASSISTED, 
like_query_certificate_number AS certificate_number_LIKE FROM t_account_bak) o, 
t_account u WHERE 
o.`certificate_number_ASSISTED`=u.`assisted_query_certificate_number` AND 
u.`assisted_query_password`=?" parameters="assist [...]
+        <output sql="SELECT u.cipher_amount AS amount, u.cipher_password AS 
password, o.certificate_number_CIPHER AS certificate_number FROM (SELECT 
cipher_certificate_number AS certificate_number_CIPHER, 
assisted_query_certificate_number AS certificate_number_ASSISTED, 
like_query_certificate_number AS certificate_number_LIKE FROM t_account_bak) o, 
t_account u WHERE 
o.certificate_number_ASSISTED=u.`assisted_query_certificate_number` AND 
u.`assisted_query_password`=?" parameters="assisted [...]
     </rewrite-assertion>
 
     <rewrite-assertion id="select_not_nested_subquery_in_table_segment_alias" 
db-types="MySQL">
@@ -39,17 +39,17 @@
 
     <rewrite-assertion 
id="select_not_nested_subquery_in_table_segment_with_shorthand_project_alias" 
db-types="MySQL">
         <input sql="SELECT u.amount, u.password, o.certificate_number FROM 
(SELECT a.* FROM t_account a) o, t_account u WHERE 
o.certificate_number=u.certificate_number AND u.password=?" parameters="1" />
-        <output sql="SELECT u.cipher_amount AS amount, u.cipher_password AS 
password, o.certificate_number_CIPHER AS certificate_number FROM (SELECT 
a.`account_id`, a.`cipher_certificate_number` AS `certificate_number_CIPHER`, 
a.`assisted_query_certificate_number` AS certificate_number_ASSISTED, 
a.`like_query_certificate_number` AS `certificate_number_LIKE`, 
a.`cipher_password` AS `password_CIPHER`, a.`assisted_query_password` AS 
password_ASSISTED, a.`like_query_password` AS `password_LI [...]
+        <output sql="SELECT u.cipher_amount AS amount, u.cipher_password AS 
password, o.certificate_number_CIPHER AS certificate_number FROM (SELECT 
a.`account_id`, a.`cipher_certificate_number` AS `certificate_number_CIPHER`, 
a.`assisted_query_certificate_number` AS certificate_number_ASSISTED, 
a.`like_query_certificate_number` AS `certificate_number_LIKE`, 
a.`cipher_password` AS `password_CIPHER`, a.`assisted_query_password` AS 
password_ASSISTED, a.`like_query_password` AS `password_LI [...]
     </rewrite-assertion>
 
     <rewrite-assertion 
id="select_not_nested_subquery_in_table_segment_with_shorthand_project_alias_quote"
 db-types="MySQL">
         <input sql="SELECT u.amount, u.password, o.certificate_number FROM 
(SELECT a.* FROM t_account `a`) o, t_account u WHERE 
o.certificate_number=u.certificate_number AND u.password=?" parameters="1" />
-        <output sql="SELECT u.cipher_amount AS amount, u.cipher_password AS 
password, o.certificate_number_CIPHER AS certificate_number FROM (SELECT 
`a`.`account_id`, `a`.`cipher_certificate_number` AS 
`certificate_number_CIPHER`, `a`.`assisted_query_certificate_number` AS 
certificate_number_ASSISTED, `a`.`like_query_certificate_number` AS 
`certificate_number_LIKE`, `a`.`cipher_password` AS `password_CIPHER`, 
`a`.`assisted_query_password` AS password_ASSISTED, `a`.`like_query_password` A 
[...]
+        <output sql="SELECT u.cipher_amount AS amount, u.cipher_password AS 
password, o.certificate_number_CIPHER AS certificate_number FROM (SELECT 
`a`.`account_id`, `a`.`cipher_certificate_number` AS 
`certificate_number_CIPHER`, `a`.`assisted_query_certificate_number` AS 
certificate_number_ASSISTED, `a`.`like_query_certificate_number` AS 
`certificate_number_LIKE`, `a`.`cipher_password` AS `password_CIPHER`, 
`a`.`assisted_query_password` AS password_ASSISTED, `a`.`like_query_password` A 
[...]
     </rewrite-assertion>
 
     <rewrite-assertion 
id="select_not_nested_subquery_in_table_segment_with_shorthand_project" 
db-types="MySQL">
         <input sql="SELECT u.amount, u.password, o.certificate_number FROM 
(SELECT * FROM t_account) o, t_account u WHERE 
o.certificate_number=u.certificate_number AND u.password=?" parameters="1" />
-        <output sql="SELECT u.cipher_amount AS amount, u.cipher_password AS 
password, o.certificate_number_CIPHER AS certificate_number FROM (SELECT 
t_account.`account_id`, t_account.`cipher_certificate_number` AS 
`certificate_number_CIPHER`, t_account.`assisted_query_certificate_number` AS 
certificate_number_ASSISTED, t_account.`like_query_certificate_number` AS 
`certificate_number_LIKE`, t_account.`cipher_password` AS `password_CIPHER`, 
t_account.`assisted_query_password` AS password_A [...]
+        <output sql="SELECT u.cipher_amount AS amount, u.cipher_password AS 
password, o.certificate_number_CIPHER AS certificate_number FROM (SELECT 
t_account.`account_id`, t_account.`cipher_certificate_number` AS 
`certificate_number_CIPHER`, t_account.`assisted_query_certificate_number` AS 
certificate_number_ASSISTED, t_account.`like_query_certificate_number` AS 
`certificate_number_LIKE`, t_account.`cipher_password` AS `password_CIPHER`, 
t_account.`assisted_query_password` AS password_A [...]
     </rewrite-assertion>
 
     <rewrite-assertion 
id="select_not_nested_subquery_in_predicate_right_equal_condition" 
db-types="MySQL">

Reply via email to