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 cd53b75 ref 14506 (#14526)
cd53b75 is described below
commit cd53b756e33668d763384a9a9b7905cb7330d5da
Author: cheese8 <[email protected]>
AuthorDate: Wed Jan 5 19:54:22 2022 +0800
ref 14506 (#14526)
* ref 14506
* fix ci
* fix ci
---
.../generator/impl/EncryptProjectionTokenGenerator.java | 14 ++++++++------
.../scenario/encrypt/case/select_for_query_with_cipher.xml | 10 ++++++++++
2 files changed, 18 insertions(+), 6 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
index 9faf4c6..f820c73 100644
---
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
+++
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
@@ -97,7 +97,7 @@ public final class EncryptProjectionTokenGenerator extends
BaseEncryptSQLTokenGe
private SubstitutableColumnNameToken generateSQLTokens(final String
tableName, final ColumnProjectionSegment columnSegment,
final
ColumnProjection columnProjection, final SubqueryType subqueryType) {
- Collection<ColumnProjection> projections =
generateProjections(tableName, columnProjection, subqueryType, false);
+ Collection<ColumnProjection> projections =
generateProjections(tableName, columnProjection, subqueryType, false, null);
int startIndex = columnSegment.getColumn().getOwner().isPresent() ?
columnSegment.getColumn().getOwner().get().getStopIndex() + 2 :
columnSegment.getColumn().getStartIndex();
int stopIndex = columnSegment.getStopIndex();
return new SubstitutableColumnNameToken(startIndex, stopIndex,
projections);
@@ -109,7 +109,7 @@ public final class EncryptProjectionTokenGenerator extends
BaseEncryptSQLTokenGe
for (ColumnProjection each : actualColumns) {
String tableName = columnTableNames.get(each.getExpression());
if (null != tableName && getEncryptRule().findEncryptor(tableName,
each.getName()).isPresent()) {
- projections.addAll(generateProjections(tableName, each,
subqueryType, true));
+ projections.addAll(generateProjections(tableName, each,
subqueryType, true, segment));
} else {
projections.add(new ColumnProjection(each.getOwner(),
each.getName(), each.getAlias().orElse(null)));
}
@@ -143,14 +143,15 @@ public final class EncryptProjectionTokenGenerator
extends BaseEncryptSQLTokenGe
return result;
}
- private Collection<ColumnProjection> generateProjections(final String
tableName, final ColumnProjection column, final SubqueryType subqueryType,
final boolean shorthand) {
+ private Collection<ColumnProjection> generateProjections(final String
tableName, final ColumnProjection column, final SubqueryType subqueryType,
final boolean shorthand,
+ final
ShorthandProjectionSegment segment) {
Collection<ColumnProjection> result = new LinkedList<>();
if (SubqueryType.PREDICATE_SUBQUERY.equals(subqueryType)) {
result.add(distinctOwner(generatePredicateSubqueryProjection(tableName,
column), shorthand));
} else if (SubqueryType.TABLE_SUBQUERY.equals(subqueryType)) {
result.addAll(generateTableSubqueryProjections(tableName, column,
shorthand));
} else {
- result.add(distinctOwner(generateCommonProjection(tableName,
column, shorthand), shorthand));
+ result.add(distinctOwner(generateCommonProjection(tableName,
column, shorthand, segment), shorthand));
}
return result;
}
@@ -188,9 +189,10 @@ public final class EncryptProjectionTokenGenerator extends
BaseEncryptSQLTokenGe
return result;
}
- private ColumnProjection generateCommonProjection(final String tableName,
final ColumnProjection column, final boolean shorthand) {
+ private ColumnProjection generateCommonProjection(final String tableName,
final ColumnProjection column, final boolean shorthand, final
ShorthandProjectionSegment segment) {
String encryptColumnName = getEncryptColumnName(tableName,
column.getName());
- return new ColumnProjection(column.getOwner(), encryptColumnName,
column.getAlias().orElse(column.getName()));
+ String owner = (segment != null && segment.getOwner().isPresent()) ?
segment.getOwner().get().getIdentifier().getValue() : column.getOwner();
+ return new ColumnProjection(owner, encryptColumnName,
column.getAlias().orElse(column.getName()));
}
private String getEncryptColumnName(final String tableName, final String
logicEncryptColumnName) {
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 4f14233..969494d 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
@@ -169,6 +169,16 @@
<output sql="SELECT u.cipher_amount AS amount, u.cipher_password AS
password, u.cipher_certificate_number AS certificate_number FROM t_account_bak
u, t_account c WHERE u.assisted_query_certificate_number IN (SELECT
assisted_query_certificate_number FROM t_account WHERE
assisted_query_password=?) AND u.assisted_query_password=?"
parameters="assisted_query_1, assisted_query_2" />
</rewrite-assertion>
+ <rewrite-assertion
id="select_not_nested_subquery_in_tablesegment_from_alias" db-types="MySQL">
+ <input sql="SELECT b.certificate_number, b.amount FROM (SELECT
a.certificate_number as certificate_number, a.amount FROM t_account a WHERE
a.amount = 1373) b" />
+ <output sql="SELECT b.cipher_certificate_number AS certificate_number,
b.cipher_amount AS amount FROM (SELECT a.cipher_certificate_number,
a.assisted_query_certificate_number, a.cipher_amount FROM t_account a WHERE
a.cipher_amount = 1373) b" />
+ </rewrite-assertion>
+
+ <rewrite-assertion
id="select_not_nested_subquery_in_tablesegment_ref_shorthand" db-types="MySQL">
+ <input sql="SELECT b.* FROM (SELECT a.certificate_number as
certificate_number, a.amount FROM t_account a WHERE a.amount = 1373) b" />
+ <output sql="SELECT `b`.`cipher_certificate_number` AS
`certificate_number`, `b`.`cipher_amount` AS `amount` FROM (SELECT
a.cipher_certificate_number, a.assisted_query_certificate_number,
a.cipher_amount FROM t_account a WHERE a.cipher_amount = 1373) b" />
+ </rewrite-assertion>
+
<rewrite-assertion
id="select_plain_with_table_level_query_with_cipher_column_for_parameters"
db-types="MySQL">
<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 = ? AND a.password = ? AND
a.amount = ? AND a.status = ?" parameters="1, aaa, 1000, 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 = ? AND a.plain_password = ? AND a.plain_amount = ? AND a.status =
?" parameters="1, aaa, 1000, OK" />