You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/09/16 15:06:21 UTC
[GitHub] [shardingsphere] cheese8 opened a new pull request #12504: Support encrypt rewrite for join table segment (SimpleTableSegment)
cheese8 opened a new pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504
Fixes #12462. @strongduanmu
Changes proposed in this pull request:
- Support encrypt rewrite for join table segment (SimpleTableSegment).
Test on those 2 cases right:
Logic SQL:
SELECT u.mobile, u.username, u.id_no, o.card_no FROM `order` o right join `user` u on o.card_no=u.id_no where o.card_no=? and u.mobile=?
√Actual SQL:
SELECT u.mobile_cipher AS mobile, u.username, u.id_no_cipher AS id_no, o.card_no_cipher AS card_no FROM `order` o right join `user` u on o.card_no_hash=u.id_no_hash where o.card_no_hash=? and u.mobile_hash=?
------------
Logic SQL:
SELECT u.mobile, u.username, u.id_no, o.card_no FROM `order` o right join `user` u on o.card_no=u.id_no join bankcard c on o.card_no=c.card_no where o.card_no=? and u.mobile=?
√Actual SQL:
SELECT u.mobile_cipher AS mobile, u.username, u.id_no_cipher AS id_no, o.card_no_cipher AS card_no FROM `order` o right join `user` u on o.card_no_hash=u.id_no_hash join bankcard c on o.card_no_hash=c.card_no where o.card_no_hash=? and u.mobile_hash=?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] codecov-commenter edited a comment on pull request #12504: Support encrypt rewrite for join table segment (SimpleTableSegment)
Posted by GitBox <gi...@apache.org>.
codecov-commenter edited a comment on pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504#issuecomment-921926307
# [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#12504](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (4aec394) into [master](https://codecov.io/gh/apache/shardingsphere/commit/09741b92e875f7d04fa38f5f9bb5898a2a70c567?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (09741b9) will **decrease** coverage by `0.27%`.
> The diff coverage is `16.14%`.
[![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/12504/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
```diff
@@ Coverage Diff @@
## master #12504 +/- ##
============================================
- Coverage 63.59% 63.32% -0.28%
- Complexity 1303 1336 +33
============================================
Files 2394 2445 +51
Lines 36430 37209 +779
Branches 6320 6432 +112
============================================
+ Hits 23168 23562 +394
- Misses 11388 11748 +360
- Partials 1874 1899 +25
```
| [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [...rypt/rewrite/condition/EncryptConditionEngine.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS9jb25kaXRpb24vRW5jcnlwdENvbmRpdGlvbkVuZ2luZS5qYXZh) | `0.00% <0.00%> (ø)` | |
| [...meter/impl/EncryptAssignmentParameterRewriter.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS9wYXJhbWV0ZXIvaW1wbC9FbmNyeXB0QXNzaWdubWVudFBhcmFtZXRlclJld3JpdGVyLmphdmE=) | `0.00% <0.00%> (ø)` | |
| [...ertOnDuplicateKeyUpdateValueParameterRewriter.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS9wYXJhbWV0ZXIvaW1wbC9FbmNyeXB0SW5zZXJ0T25EdXBsaWNhdGVLZXlVcGRhdGVWYWx1ZVBhcmFtZXRlclJld3JpdGVyLmphdmE=) | `0.00% <0.00%> (ø)` | |
| [...eter/impl/EncryptInsertValueParameterRewriter.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS9wYXJhbWV0ZXIvaW1wbC9FbmNyeXB0SW5zZXJ0VmFsdWVQYXJhbWV0ZXJSZXdyaXRlci5qYXZh) | `0.00% <0.00%> (ø)` | |
| [...ameter/impl/EncryptPredicateParameterRewriter.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS9wYXJhbWV0ZXIvaW1wbC9FbmNyeXB0UHJlZGljYXRlUGFyYW1ldGVyUmV3cml0ZXIuamF2YQ==) | `0.00% <0.00%> (ø)` | |
| [...enerator/impl/EncryptAssignmentTokenGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS90b2tlbi9nZW5lcmF0b3IvaW1wbC9FbmNyeXB0QXNzaWdubWVudFRva2VuR2VuZXJhdG9yLmphdmE=) | `0.00% <0.00%> (ø)` | |
| [...ator/impl/EncryptInsertOnUpdateTokenGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS90b2tlbi9nZW5lcmF0b3IvaW1wbC9FbmNyeXB0SW5zZXJ0T25VcGRhdGVUb2tlbkdlbmVyYXRvci5qYXZh) | `0.00% <0.00%> (ø)` | |
| [...erator/impl/EncryptInsertValuesTokenGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS90b2tlbi9nZW5lcmF0b3IvaW1wbC9FbmNyeXB0SW5zZXJ0VmFsdWVzVG9rZW5HZW5lcmF0b3IuamF2YQ==) | `0.00% <0.00%> (ø)` | |
| [...tor/impl/EncryptPredicateColumnTokenGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS90b2tlbi9nZW5lcmF0b3IvaW1wbC9FbmNyeXB0UHJlZGljYXRlQ29sdW1uVG9rZW5HZW5lcmF0b3IuamF2YQ==) | `0.00% <0.00%> (ø)` | |
| [...impl/EncryptPredicateRightValueTokenGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS90b2tlbi9nZW5lcmF0b3IvaW1wbC9FbmNyeXB0UHJlZGljYXRlUmlnaHRWYWx1ZVRva2VuR2VuZXJhdG9yLmphdmE=) | `0.00% <0.00%> (ø)` | |
| ... and [282 more](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [c1c878a...4aec394](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] strongduanmu commented on a change in pull request #12504: Support encrypt rewrite for join table segment (SimpleTableSegment)
Posted by GitBox <gi...@apache.org>.
strongduanmu commented on a change in pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504#discussion_r715720601
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
##########
@@ -63,10 +75,19 @@ protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStat
@Override
public Collection<SubstitutableColumnNameToken> generateSQLTokens(final SelectStatementContext selectStatementContext) {
ProjectionsSegment projectionsSegment = selectStatementContext.getSqlStatement().getProjections();
- // TODO process multiple tables
- String tableName = selectStatementContext.getAllTables().iterator().next().getTableName().getIdentifier().getValue();
- return getEncryptRule().findEncryptTable(tableName).map(
- encryptTable -> generateSQLTokens(projectionsSegment, tableName, selectStatementContext, encryptTable)).orElseGet(Collections::emptyList);
+ Collection<SubstitutableColumnNameToken> result = new HashSet<>();
+ Collection<String> tableNames = selectStatementContext.getTablesContext().getTableNames();
+ for (String each : tableNames) {
+ Optional<EncryptTable> encryptTable = getEncryptRule().findEncryptTable(each);
+ if (encryptTable.isPresent()) {
+ Collection<SubstitutableColumnNameToken> sqlTokens = generateSQLTokens(projectionsSegment, each, selectStatementContext, encryptTable.get());
+ result.addAll(sqlTokens);
+ }
+ }
+ if (selectStatementContext.isContainsJoinQuery()) {
Review comment:
If it is to deal with the rewriting in the join condition, please move it to `EncryptPredicateColumnTokenGenerator`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] cheese8 commented on a change in pull request #12504: Support encrypt rewrite for join table segment (SimpleTableSegment)
Posted by GitBox <gi...@apache.org>.
cheese8 commented on a change in pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504#discussion_r717321396
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptPredicateColumnTokenGenerator.java
##########
@@ -56,57 +59,82 @@
@Override
protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStatementContext) {
+ return isGenerateSQLTokenForEncryptOnWhereAvailable(sqlStatementContext) || isGenerateSQLTokenForEncryptOnJoinSegments(sqlStatementContext);
+ }
+
+ private boolean isGenerateSQLTokenForEncryptOnWhereAvailable(final SQLStatementContext sqlStatementContext) {
return sqlStatementContext instanceof WhereAvailable && ((WhereAvailable) sqlStatementContext).getWhere().isPresent();
}
+ private boolean isGenerateSQLTokenForEncryptOnJoinSegments(final SQLStatementContext sqlStatementContext) {
+ return sqlStatementContext instanceof SelectStatementContext && !WhereExtractUtil.getJoinWhereSegments((SelectStatement) sqlStatementContext.getSqlStatement()).isEmpty();
Review comment:
fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] strongduanmu commented on pull request #12504: Support encrypt rewrite for join table segment (SimpleTableSegment)
Posted by GitBox <gi...@apache.org>.
strongduanmu commented on pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504#issuecomment-921340411
Hi @cheese8, I'm glad to see your second pr. can you fix ci error first?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] cheese8 commented on a change in pull request #12504: Support encrypt rewrite for join table segment (SimpleTableSegment)
Posted by GitBox <gi...@apache.org>.
cheese8 commented on a change in pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504#discussion_r716136783
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
##########
@@ -63,10 +75,19 @@ protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStat
@Override
public Collection<SubstitutableColumnNameToken> generateSQLTokens(final SelectStatementContext selectStatementContext) {
ProjectionsSegment projectionsSegment = selectStatementContext.getSqlStatement().getProjections();
- // TODO process multiple tables
- String tableName = selectStatementContext.getAllTables().iterator().next().getTableName().getIdentifier().getValue();
- return getEncryptRule().findEncryptTable(tableName).map(
- encryptTable -> generateSQLTokens(projectionsSegment, tableName, selectStatementContext, encryptTable)).orElseGet(Collections::emptyList);
+ Collection<SubstitutableColumnNameToken> result = new HashSet<>();
+ Collection<String> tableNames = selectStatementContext.getTablesContext().getTableNames();
+ for (String each : tableNames) {
+ Optional<EncryptTable> encryptTable = getEncryptRule().findEncryptTable(each);
+ if (encryptTable.isPresent()) {
+ Collection<SubstitutableColumnNameToken> sqlTokens = generateSQLTokens(projectionsSegment, each, selectStatementContext, encryptTable.get());
+ result.addAll(sqlTokens);
+ }
+ }
+ if (selectStatementContext.isContainsJoinQuery()) {
Review comment:
fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] strongduanmu commented on a change in pull request #12504: Support encrypt rewrite for join table segment (SimpleTableSegment)
Posted by GitBox <gi...@apache.org>.
strongduanmu commented on a change in pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504#discussion_r716326231
##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/WhereExtractUtil.java
##########
@@ -47,14 +51,38 @@
return Collections.emptyList();
}
TableSegment tableSegment = selectStatement.getFrom();
- Collection<WhereSegment> result = new LinkedList<>();
- if (tableSegment instanceof JoinTableSegment && null != ((JoinTableSegment) tableSegment).getCondition()) {
- ExpressionSegment expressionSegment = ((JoinTableSegment) tableSegment).getCondition();
- WhereSegment whereSegment = new WhereSegment(expressionSegment.getStartIndex(), expressionSegment.getStopIndex(), expressionSegment);
- result.add(whereSegment);
+ Collection<WhereSegment> result = new HashSet<>();
+
+ if (!(tableSegment instanceof JoinTableSegment) || null == ((JoinTableSegment) tableSegment).getCondition()) {
+ return Collections.emptyList();
+ }
+
+ JoinTableSegment joinTableSegment = (JoinTableSegment) tableSegment;
+ ExpressionSegment leftCondition = joinTableSegment.getCondition();
Review comment:
@cheese8 Can we optimize this logic by recursive JoinTableSegment?
##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/ColumnExtractor.java
##########
@@ -54,4 +59,35 @@
}
return Optional.empty();
}
+
+ /**
+ * Get left and right value if either value of expression is column segment.
+ *
+ * @param expression expression segment
+ * @return column segment collection
+ */
+ public static Collection<ColumnSegment> extractAll(final ExpressionSegment expression) {
+ if (expression instanceof BinaryOperationExpression) {
+ BinaryOperationExpression boExpression = (BinaryOperationExpression) expression;
+ Collection<ColumnSegment> columns = new ArrayList<>();
+ if (Objects.nonNull(boExpression.getLeft()) && boExpression.getLeft() instanceof ColumnSegment) {
Review comment:
@cheese8 `Objects.nonNull(boExpression.getLeft())` is useless, can we remove it?
##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/ColumnExtractor.java
##########
@@ -54,4 +59,35 @@
}
return Optional.empty();
}
+
+ /**
+ * Get left and right value if either value of expression is column segment.
+ *
+ * @param expression expression segment
+ * @return column segment collection
+ */
+ public static Collection<ColumnSegment> extractAll(final ExpressionSegment expression) {
+ if (expression instanceof BinaryOperationExpression) {
+ BinaryOperationExpression boExpression = (BinaryOperationExpression) expression;
+ Collection<ColumnSegment> columns = new ArrayList<>();
+ if (Objects.nonNull(boExpression.getLeft()) && boExpression.getLeft() instanceof ColumnSegment) {
+ columns.add((ColumnSegment) boExpression.getLeft());
+ }
+ if (Objects.nonNull(boExpression.getRight()) && boExpression.getRight() instanceof ColumnSegment) {
+ columns.add((ColumnSegment) boExpression.getRight());
+ }
+ return columns;
+ }
+ if (expression instanceof InExpression && Objects.nonNull(((InExpression) expression).getLeft())
+ && ((InExpression) expression).getLeft() instanceof ColumnSegment) {
+ ColumnSegment column = (ColumnSegment) ((InExpression) expression).getLeft();
+ return Arrays.asList(column);
+ }
+ if (expression instanceof BetweenExpression && Objects.nonNull(((BetweenExpression) expression).getLeft())
+ && ((BetweenExpression) expression).getLeft() instanceof ColumnSegment) {
+ ColumnSegment column = (ColumnSegment) ((BetweenExpression) expression).getLeft();
+ return Arrays.asList(column);
+ }
+ return Collections.emptyList();
Review comment:
@cheese8 Maybe add a param `result` to store the result is better.
```java
Collection<ColumnSegment> result = new LinkedList<>();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] cheese8 commented on a change in pull request #12504: Support encrypt rewrite for join table segment (SimpleTableSegment)
Posted by GitBox <gi...@apache.org>.
cheese8 commented on a change in pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504#discussion_r716136669
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptPredicateColumnTokenGenerator.java
##########
@@ -66,47 +67,53 @@ protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStat
ExpressionSegment expression = ((WhereAvailable) sqlStatementContext).getWhere().get().getExpr();
Collection<AndPredicate> andPredicates = ExpressionExtractUtil.getAndPredicates(expression);
Map<String, String> columnTableNames = getColumnTableNames(sqlStatementContext, andPredicates);
- for (AndPredicate each : andPredicates) {
- result.addAll(generateSQLTokens(each.getPredicates(), columnTableNames));
- }
+ andPredicates.forEach(each -> result.addAll(generateSQLTokens(each.getPredicates(), columnTableNames)));
Review comment:
no change, but using lambda
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] strongduanmu commented on a change in pull request #12504: Support encrypt rewrite for join table segment (SimpleTableSegment)
Posted by GitBox <gi...@apache.org>.
strongduanmu commented on a change in pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504#discussion_r711579605
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
##########
@@ -88,6 +111,90 @@ protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStat
return result;
}
+ private Map<String, SimpleTableSegment> distinct(final Collection<SimpleTableSegment> simpleTableSegments) {
Review comment:
@cheese8 Does this method just for distinct? If so, you can use `TablesContext.uniqueTables`.
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptPredicateColumnTokenGenerator.java
##########
@@ -75,35 +77,43 @@ protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStat
private Collection<SubstitutableColumnNameToken> generateSQLTokens(final Collection<ExpressionSegment> predicates, final Map<String, String> columnTableNames) {
Collection<SubstitutableColumnNameToken> result = new LinkedList<>();
for (ExpressionSegment each : predicates) {
- Optional<ColumnSegment> column = ColumnExtractor.extract(each);
- if (!column.isPresent()) {
- continue;
- }
- Optional<EncryptTable> encryptTable = findEncryptTable(columnTableNames, column.get());
- if (!encryptTable.isPresent() || !encryptTable.get().findEncryptorName(column.get().getIdentifier().getValue()).isPresent()) {
- continue;
- }
- int startIndex = column.get().getOwner().isPresent() ? column.get().getOwner().get().getStopIndex() + 2 : column.get().getStartIndex();
- int stopIndex = column.get().getStopIndex();
- if (!queryWithCipherColumn) {
- Optional<String> plainColumn = encryptTable.get().findPlainColumn(column.get().getIdentifier().getValue());
- if (plainColumn.isPresent()) {
- result.add(new SubstitutableColumnNameToken(startIndex, stopIndex, getColumnProjections(plainColumn.get())));
+ Collection<Optional<ColumnSegment>> columns = ColumnExtractor.extractAll(each);
+ for (Optional<ColumnSegment> column : columns) {
+ if (!column.isPresent()) {
+ continue;
+ }
+ Optional<EncryptTable> encryptTable = findEncryptTable(columnTableNames, column.get());
+ if (!encryptTable.isPresent() || !encryptTable.get().findEncryptorName(column.get().getIdentifier().getValue()).isPresent()) {
continue;
}
+ int startIndex = column.get().getOwner().isPresent() ? column.get().getOwner().get().getStopIndex() + 2 : column.get().getStartIndex();
+ int stopIndex = column.get().getStopIndex();
+ if (!queryWithCipherColumn) {
+ Optional<String> plainColumn = encryptTable.get().findPlainColumn(column.get().getIdentifier().getValue());
+ if (plainColumn.isPresent()) {
+ result.add(new SubstitutableColumnNameToken(startIndex, stopIndex, getColumnProjections(plainColumn.get())));
+ continue;
+ }
+ }
+ Optional<String> assistedQueryColumn = encryptTable.get().findAssistedQueryColumn(column.get().getIdentifier().getValue());
+ SubstitutableColumnNameToken encryptColumnNameToken = assistedQueryColumn.map(columnName
+ -> new SubstitutableColumnNameToken(startIndex, stopIndex, getColumnProjections(columnName))).orElseGet(()
+ -> new SubstitutableColumnNameToken(startIndex, stopIndex, getColumnProjections(encryptTable.get().getCipherColumn(column.get().getIdentifier().getValue()))));
+ result.add(encryptColumnNameToken);
}
- Optional<String> assistedQueryColumn = encryptTable.get().findAssistedQueryColumn(column.get().getIdentifier().getValue());
- SubstitutableColumnNameToken encryptColumnNameToken = assistedQueryColumn.map(columnName
- -> new SubstitutableColumnNameToken(startIndex, stopIndex, getColumnProjections(columnName))).orElseGet(()
- -> new SubstitutableColumnNameToken(startIndex, stopIndex, getColumnProjections(encryptTable.get().getCipherColumn(column.get().getIdentifier().getValue()))));
- result.add(encryptColumnNameToken);
}
return result;
}
private Map<String, String> getColumnTableNames(final SQLStatementContext sqlStatementContext, final Collection<AndPredicate> andPredicates) {
- Collection<ColumnSegment> columns = andPredicates.stream().flatMap(each -> each.getPredicates().stream())
- .map(each -> ColumnExtractor.extract(each).orElse(null)).filter(Objects::nonNull).collect(Collectors.toList());
+ Collection<ColumnSegment> columns = new ArrayList<ColumnSegment>();
+ for (AndPredicate andPredicate : andPredicates) {
Review comment:
@cheese8 Use `each` may be better.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] strongduanmu commented on a change in pull request #12504: Support encrypt rewrite for join table segment (SimpleTableSegment)
Posted by GitBox <gi...@apache.org>.
strongduanmu commented on a change in pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504#discussion_r715713321
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
##########
@@ -63,10 +75,19 @@ protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStat
@Override
public Collection<SubstitutableColumnNameToken> generateSQLTokens(final SelectStatementContext selectStatementContext) {
ProjectionsSegment projectionsSegment = selectStatementContext.getSqlStatement().getProjections();
- // TODO process multiple tables
- String tableName = selectStatementContext.getAllTables().iterator().next().getTableName().getIdentifier().getValue();
- return getEncryptRule().findEncryptTable(tableName).map(
- encryptTable -> generateSQLTokens(projectionsSegment, tableName, selectStatementContext, encryptTable)).orElseGet(Collections::emptyList);
+ Collection<SubstitutableColumnNameToken> result = new HashSet<>();
+ Collection<String> tableNames = selectStatementContext.getTablesContext().getTableNames();
+ for (String each : tableNames) {
+ Optional<EncryptTable> encryptTable = getEncryptRule().findEncryptTable(each);
+ if (encryptTable.isPresent()) {
+ Collection<SubstitutableColumnNameToken> sqlTokens = generateSQLTokens(projectionsSegment, each, selectStatementContext, encryptTable.get());
+ result.addAll(sqlTokens);
+ }
+ }
+ if (selectStatementContext.isContainsJoinQuery()) {
Review comment:
@cheese8 Why do you need to process the associated query separately instead of in the general generateSQLTokens method above?
##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/TableExtractor.java
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+
+package org.apache.shardingsphere.sql.parser.sql.common.util;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Table extractor.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class TableExtractor {
Review comment:
@cheese8 Please consider move this logic to TablesContext.
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptPredicateColumnTokenGenerator.java
##########
@@ -66,47 +67,53 @@ protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStat
ExpressionSegment expression = ((WhereAvailable) sqlStatementContext).getWhere().get().getExpr();
Collection<AndPredicate> andPredicates = ExpressionExtractUtil.getAndPredicates(expression);
Map<String, String> columnTableNames = getColumnTableNames(sqlStatementContext, andPredicates);
- for (AndPredicate each : andPredicates) {
- result.addAll(generateSQLTokens(each.getPredicates(), columnTableNames));
- }
+ andPredicates.forEach(each -> result.addAll(generateSQLTokens(each.getPredicates(), columnTableNames)));
return result;
}
- private Collection<SubstitutableColumnNameToken> generateSQLTokens(final Collection<ExpressionSegment> predicates, final Map<String, String> columnTableNames) {
Review comment:
@cheese8 Please keep the original param predicates.
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptPredicateColumnTokenGenerator.java
##########
@@ -66,47 +67,53 @@ protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStat
ExpressionSegment expression = ((WhereAvailable) sqlStatementContext).getWhere().get().getExpr();
Collection<AndPredicate> andPredicates = ExpressionExtractUtil.getAndPredicates(expression);
Map<String, String> columnTableNames = getColumnTableNames(sqlStatementContext, andPredicates);
- for (AndPredicate each : andPredicates) {
- result.addAll(generateSQLTokens(each.getPredicates(), columnTableNames));
- }
+ andPredicates.forEach(each -> result.addAll(generateSQLTokens(each.getPredicates(), columnTableNames)));
Review comment:
@cheese8 What is the difference between this change and the original logic?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] strongduanmu merged pull request #12504: Support encrypt rewrite for join table segment (SimpleTableSegment)
Posted by GitBox <gi...@apache.org>.
strongduanmu merged pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] codecov-commenter edited a comment on pull request #12504: Support encrypt rewrite for join table segment (SimpleTableSegment)
Posted by GitBox <gi...@apache.org>.
codecov-commenter edited a comment on pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504#issuecomment-921926307
# [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#12504](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (75313aa) into [master](https://codecov.io/gh/apache/shardingsphere/commit/09741b92e875f7d04fa38f5f9bb5898a2a70c567?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (09741b9) will **decrease** coverage by `0.30%`.
> The diff coverage is `15.04%`.
[![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/12504/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
```diff
@@ Coverage Diff @@
## master #12504 +/- ##
============================================
- Coverage 63.59% 63.29% -0.31%
- Complexity 1303 1309 +6
============================================
Files 2394 2414 +20
Lines 36430 36884 +454
Branches 6320 6414 +94
============================================
+ Hits 23168 23346 +178
- Misses 11388 11641 +253
- Partials 1874 1897 +23
```
| [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [...rypt/rewrite/condition/EncryptConditionEngine.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS9jb25kaXRpb24vRW5jcnlwdENvbmRpdGlvbkVuZ2luZS5qYXZh) | `0.00% <0.00%> (ø)` | |
| [...meter/impl/EncryptAssignmentParameterRewriter.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS9wYXJhbWV0ZXIvaW1wbC9FbmNyeXB0QXNzaWdubWVudFBhcmFtZXRlclJld3JpdGVyLmphdmE=) | `0.00% <0.00%> (ø)` | |
| [...ertOnDuplicateKeyUpdateValueParameterRewriter.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS9wYXJhbWV0ZXIvaW1wbC9FbmNyeXB0SW5zZXJ0T25EdXBsaWNhdGVLZXlVcGRhdGVWYWx1ZVBhcmFtZXRlclJld3JpdGVyLmphdmE=) | `0.00% <0.00%> (ø)` | |
| [...eter/impl/EncryptInsertValueParameterRewriter.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS9wYXJhbWV0ZXIvaW1wbC9FbmNyeXB0SW5zZXJ0VmFsdWVQYXJhbWV0ZXJSZXdyaXRlci5qYXZh) | `0.00% <0.00%> (ø)` | |
| [...ameter/impl/EncryptPredicateParameterRewriter.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS9wYXJhbWV0ZXIvaW1wbC9FbmNyeXB0UHJlZGljYXRlUGFyYW1ldGVyUmV3cml0ZXIuamF2YQ==) | `0.00% <0.00%> (ø)` | |
| [...enerator/impl/EncryptAssignmentTokenGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS90b2tlbi9nZW5lcmF0b3IvaW1wbC9FbmNyeXB0QXNzaWdubWVudFRva2VuR2VuZXJhdG9yLmphdmE=) | `0.00% <0.00%> (ø)` | |
| [...ator/impl/EncryptInsertOnUpdateTokenGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS90b2tlbi9nZW5lcmF0b3IvaW1wbC9FbmNyeXB0SW5zZXJ0T25VcGRhdGVUb2tlbkdlbmVyYXRvci5qYXZh) | `0.00% <0.00%> (ø)` | |
| [...erator/impl/EncryptInsertValuesTokenGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS90b2tlbi9nZW5lcmF0b3IvaW1wbC9FbmNyeXB0SW5zZXJ0VmFsdWVzVG9rZW5HZW5lcmF0b3IuamF2YQ==) | `0.00% <0.00%> (ø)` | |
| [...tor/impl/EncryptPredicateColumnTokenGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS90b2tlbi9nZW5lcmF0b3IvaW1wbC9FbmNyeXB0UHJlZGljYXRlQ29sdW1uVG9rZW5HZW5lcmF0b3IuamF2YQ==) | `0.00% <0.00%> (ø)` | |
| [...impl/EncryptPredicateRightValueTokenGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS90b2tlbi9nZW5lcmF0b3IvaW1wbC9FbmNyeXB0UHJlZGljYXRlUmlnaHRWYWx1ZVRva2VuR2VuZXJhdG9yLmphdmE=) | `0.00% <0.00%> (ø)` | |
| ... and [140 more](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [c1c878a...75313aa](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] strongduanmu commented on a change in pull request #12504: Support encrypt rewrite for join table segment (SimpleTableSegment)
Posted by GitBox <gi...@apache.org>.
strongduanmu commented on a change in pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504#discussion_r716301816
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptPredicateColumnTokenGenerator.java
##########
@@ -56,57 +59,82 @@
@Override
protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStatementContext) {
+ return isGenerateSQLTokenForEncryptOnWhereAvailable(sqlStatementContext) || isGenerateSQLTokenForEncryptOnJoinSegments(sqlStatementContext);
+ }
+
+ private boolean isGenerateSQLTokenForEncryptOnWhereAvailable(final SQLStatementContext sqlStatementContext) {
return sqlStatementContext instanceof WhereAvailable && ((WhereAvailable) sqlStatementContext).getWhere().isPresent();
}
+ private boolean isGenerateSQLTokenForEncryptOnJoinSegments(final SQLStatementContext sqlStatementContext) {
+ return sqlStatementContext instanceof SelectStatementContext && !WhereExtractUtil.getJoinWhereSegments((SelectStatement) sqlStatementContext.getSqlStatement()).isEmpty();
+ }
+
@Override
public Collection<SubstitutableColumnNameToken> generateSQLTokens(final SQLStatementContext sqlStatementContext) {
- Preconditions.checkState(((WhereAvailable) sqlStatementContext).getWhere().isPresent());
Collection<SubstitutableColumnNameToken> result = new LinkedHashSet<>();
- ExpressionSegment expression = ((WhereAvailable) sqlStatementContext).getWhere().get().getExpr();
- Collection<AndPredicate> andPredicates = ExpressionExtractUtil.getAndPredicates(expression);
- Map<String, String> columnTableNames = getColumnTableNames(sqlStatementContext, andPredicates);
- for (AndPredicate each : andPredicates) {
- result.addAll(generateSQLTokens(each.getPredicates(), columnTableNames));
+ Collection<AndPredicate> andPredicates = new LinkedHashSet<>();
+ if (isGenerateSQLTokenForEncryptOnWhereAvailable(sqlStatementContext)) {
+ ExpressionSegment expression = ((WhereAvailable) sqlStatementContext).getWhere().get().getExpr();
+ andPredicates.addAll(ExpressionExtractUtil.getAndPredicates(expression));
}
+ Optional<Collection<WhereSegment>> whereSegments = Optional.empty();
+ if (sqlStatementContext instanceof SelectStatementContext) {
+ whereSegments = Optional.of(WhereExtractUtil.getJoinWhereSegments((SelectStatement) sqlStatementContext.getSqlStatement()));
Review comment:
Why add `Optional` here?
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptPredicateColumnTokenGenerator.java
##########
@@ -56,57 +59,82 @@
@Override
protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStatementContext) {
+ return isGenerateSQLTokenForEncryptOnWhereAvailable(sqlStatementContext) || isGenerateSQLTokenForEncryptOnJoinSegments(sqlStatementContext);
+ }
+
+ private boolean isGenerateSQLTokenForEncryptOnWhereAvailable(final SQLStatementContext sqlStatementContext) {
return sqlStatementContext instanceof WhereAvailable && ((WhereAvailable) sqlStatementContext).getWhere().isPresent();
}
+ private boolean isGenerateSQLTokenForEncryptOnJoinSegments(final SQLStatementContext sqlStatementContext) {
+ return sqlStatementContext instanceof SelectStatementContext && !WhereExtractUtil.getJoinWhereSegments((SelectStatement) sqlStatementContext.getSqlStatement()).isEmpty();
Review comment:
@cheese8 Can it be replaced by the `isContainsJoinQuery` method?
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
##########
@@ -63,10 +65,16 @@ protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStat
@Override
public Collection<SubstitutableColumnNameToken> generateSQLTokens(final SelectStatementContext selectStatementContext) {
ProjectionsSegment projectionsSegment = selectStatementContext.getSqlStatement().getProjections();
- // TODO process multiple tables
- String tableName = selectStatementContext.getAllTables().iterator().next().getTableName().getIdentifier().getValue();
- return getEncryptRule().findEncryptTable(tableName).map(
- encryptTable -> generateSQLTokens(projectionsSegment, tableName, selectStatementContext, encryptTable)).orElseGet(Collections::emptyList);
+ Collection<SubstitutableColumnNameToken> result = new HashSet<>();
+ Collection<String> tableNames = selectStatementContext.getTablesContext().getTableNames();
+ for (String each : tableNames) {
+ Optional<EncryptTable> encryptTable = getEncryptRule().findEncryptTable(each);
+ if (encryptTable.isPresent()) {
+ Collection<SubstitutableColumnNameToken> sqlTokens = generateSQLTokens(projectionsSegment, each, selectStatementContext, encryptTable.get());
Review comment:
@cheese8 `result.add(generateSQLTokens(projectionsSegment, each, selectStatementContext, encryptTable.get()))` is better.
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptPredicateColumnTokenGenerator.java
##########
@@ -56,57 +59,82 @@
@Override
protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStatementContext) {
+ return isGenerateSQLTokenForEncryptOnWhereAvailable(sqlStatementContext) || isGenerateSQLTokenForEncryptOnJoinSegments(sqlStatementContext);
+ }
+
+ private boolean isGenerateSQLTokenForEncryptOnWhereAvailable(final SQLStatementContext sqlStatementContext) {
return sqlStatementContext instanceof WhereAvailable && ((WhereAvailable) sqlStatementContext).getWhere().isPresent();
}
+ private boolean isGenerateSQLTokenForEncryptOnJoinSegments(final SQLStatementContext sqlStatementContext) {
+ return sqlStatementContext instanceof SelectStatementContext && !WhereExtractUtil.getJoinWhereSegments((SelectStatement) sqlStatementContext.getSqlStatement()).isEmpty();
+ }
+
@Override
public Collection<SubstitutableColumnNameToken> generateSQLTokens(final SQLStatementContext sqlStatementContext) {
- Preconditions.checkState(((WhereAvailable) sqlStatementContext).getWhere().isPresent());
Collection<SubstitutableColumnNameToken> result = new LinkedHashSet<>();
- ExpressionSegment expression = ((WhereAvailable) sqlStatementContext).getWhere().get().getExpr();
- Collection<AndPredicate> andPredicates = ExpressionExtractUtil.getAndPredicates(expression);
- Map<String, String> columnTableNames = getColumnTableNames(sqlStatementContext, andPredicates);
- for (AndPredicate each : andPredicates) {
- result.addAll(generateSQLTokens(each.getPredicates(), columnTableNames));
+ Collection<AndPredicate> andPredicates = new LinkedHashSet<>();
+ if (isGenerateSQLTokenForEncryptOnWhereAvailable(sqlStatementContext)) {
+ ExpressionSegment expression = ((WhereAvailable) sqlStatementContext).getWhere().get().getExpr();
+ andPredicates.addAll(ExpressionExtractUtil.getAndPredicates(expression));
}
+ Optional<Collection<WhereSegment>> whereSegments = Optional.empty();
+ if (sqlStatementContext instanceof SelectStatementContext) {
+ whereSegments = Optional.of(WhereExtractUtil.getJoinWhereSegments((SelectStatement) sqlStatementContext.getSqlStatement()));
+ whereSegments.get().forEach(each -> andPredicates.addAll(ExpressionExtractUtil.getAndPredicates(each.getExpr())));
+ }
+ Map<String, String> columnTableNames = getColumnTableNames(sqlStatementContext, andPredicates, whereSegments);
+ andPredicates.forEach(each -> result.addAll(generateSQLTokens(each.getPredicates(), columnTableNames)));
Review comment:
@cheese8 Can we use stream api to replace foreach?
##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/predicate/WhereSegment.java
##########
@@ -29,6 +31,7 @@
@RequiredArgsConstructor
@Getter
@Setter
+@EqualsAndHashCode
Review comment:
@cheese8 Why add this annotation?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] strongduanmu commented on a change in pull request #12504: Support encrypt rewrite for join table segment (SimpleTableSegment)
Posted by GitBox <gi...@apache.org>.
strongduanmu commented on a change in pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504#discussion_r713607277
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptPredicateColumnTokenGenerator.java
##########
@@ -75,38 +78,54 @@ protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStat
private Collection<SubstitutableColumnNameToken> generateSQLTokens(final Collection<ExpressionSegment> predicates, final Map<String, String> columnTableNames) {
Collection<SubstitutableColumnNameToken> result = new LinkedList<>();
for (ExpressionSegment each : predicates) {
- Optional<ColumnSegment> column = ColumnExtractor.extract(each);
- if (!column.isPresent()) {
+ result.addAll(processColumnSegment(ColumnExtractor.extractAll(each), columnTableNames));
+ }
+ return result;
+ }
+
+ private List<SubstitutableColumnNameToken> processColumnSegment(final Collection<Optional<ColumnSegment>> columnSegments, final Map<String, String> columnTableNames) {
Review comment:
@cheese8 Do you think `generateSQLTokens` is better?
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptPredicateColumnTokenGenerator.java
##########
@@ -75,38 +78,54 @@ protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStat
private Collection<SubstitutableColumnNameToken> generateSQLTokens(final Collection<ExpressionSegment> predicates, final Map<String, String> columnTableNames) {
Collection<SubstitutableColumnNameToken> result = new LinkedList<>();
for (ExpressionSegment each : predicates) {
- Optional<ColumnSegment> column = ColumnExtractor.extract(each);
- if (!column.isPresent()) {
+ result.addAll(processColumnSegment(ColumnExtractor.extractAll(each), columnTableNames));
+ }
+ return result;
+ }
+
+ private List<SubstitutableColumnNameToken> processColumnSegment(final Collection<Optional<ColumnSegment>> columnSegments, final Map<String, String> columnTableNames) {
+ List<SubstitutableColumnNameToken> result = new LinkedList<>();
+ for (Optional<ColumnSegment> each : columnSegments) {
+ if (!each.isPresent()) {
continue;
}
- Optional<EncryptTable> encryptTable = findEncryptTable(columnTableNames, column.get());
- if (!encryptTable.isPresent() || !encryptTable.get().findEncryptorName(column.get().getIdentifier().getValue()).isPresent()) {
+ Optional<EncryptTable> encryptTable = findEncryptTable(columnTableNames, each.get());
+ if (!encryptTable.isPresent() || !encryptTable.get().findEncryptorName(each.get().getIdentifier().getValue()).isPresent()) {
continue;
}
- int startIndex = column.get().getOwner().isPresent() ? column.get().getOwner().get().getStopIndex() + 2 : column.get().getStartIndex();
- int stopIndex = column.get().getStopIndex();
+ int startIndex = each.get().getOwner().isPresent() ? each.get().getOwner().get().getStopIndex() + 2 : each.get().getStartIndex();
+ int stopIndex = each.get().getStopIndex();
if (!queryWithCipherColumn) {
- Optional<String> plainColumn = encryptTable.get().findPlainColumn(column.get().getIdentifier().getValue());
+ Optional<String> plainColumn = encryptTable.get().findPlainColumn(each.get().getIdentifier().getValue());
if (plainColumn.isPresent()) {
result.add(new SubstitutableColumnNameToken(startIndex, stopIndex, getColumnProjections(plainColumn.get())));
continue;
}
}
- Optional<String> assistedQueryColumn = encryptTable.get().findAssistedQueryColumn(column.get().getIdentifier().getValue());
+ Optional<String> assistedQueryColumn = encryptTable.get().findAssistedQueryColumn(each.get().getIdentifier().getValue());
SubstitutableColumnNameToken encryptColumnNameToken = assistedQueryColumn.map(columnName
-> new SubstitutableColumnNameToken(startIndex, stopIndex, getColumnProjections(columnName))).orElseGet(()
- -> new SubstitutableColumnNameToken(startIndex, stopIndex, getColumnProjections(encryptTable.get().getCipherColumn(column.get().getIdentifier().getValue()))));
+ -> new SubstitutableColumnNameToken(startIndex, stopIndex, getColumnProjections(encryptTable.get().getCipherColumn(each.get().getIdentifier().getValue()))));
result.add(encryptColumnNameToken);
}
return result;
}
private Map<String, String> getColumnTableNames(final SQLStatementContext sqlStatementContext, final Collection<AndPredicate> andPredicates) {
- Collection<ColumnSegment> columns = andPredicates.stream().flatMap(each -> each.getPredicates().stream())
- .map(each -> ColumnExtractor.extract(each).orElse(null)).filter(Objects::nonNull).collect(Collectors.toList());
+ Collection<ColumnSegment> columns = new ArrayList<ColumnSegment>();
+ andPredicates.forEach(each -> columns.addAll(processExpressionSegment(each.getPredicates())));
return sqlStatementContext.getTablesContext().findTableName(columns, schema);
}
+ private Collection<ColumnSegment> processExpressionSegment(final Collection<ExpressionSegment> predicates) {
Review comment:
@cheese8 Please use stream api to replace this method
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
##########
@@ -88,6 +111,71 @@ protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStat
return result;
}
+ private List<SubstitutableColumnNameToken> distinct(final List<SubstitutableColumnNameToken> substitutableColumnNameTokenList) {
+ Map<String, SubstitutableColumnNameToken> distinctMap = new HashMap<>();
+ for (SubstitutableColumnNameToken each : substitutableColumnNameTokenList) {
+ String key = each.getStartIndex() + "," + each.getStartIndex();
+ if (!distinctMap.containsKey(key)) {
+ distinctMap.put(key, each);
+ }
+ }
+ return new LinkedList<>(distinctMap.values());
+ }
+
+ private Collection<SubstitutableColumnNameToken> processJoinTableSegments(final SelectStatementContext selectStatementContext,
Review comment:
@cheese8 `generateSQLTokens` may be better.
##########
File path: shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/select_for_query_with_cipher.xml
##########
@@ -56,14 +56,14 @@
<rewrite-assertion id="select_with_sharding_qualified_shorthand_join_table">
<input sql="SELECT b.* FROM t_account a, t_account_detail b where a.password = b.password" />
- <output sql="SELECT b.* FROM t_account_0 a, t_account_detail_0 b where a.assisted_query_password = b.password" />
- <output sql="SELECT b.* FROM t_account_1 a, t_account_detail_1 b where a.assisted_query_password = b.password" />
+ <output sql="SELECT b.* FROM t_account_0 a, t_account_detail_0 b where a.assisted_query_password = b.assisted_query_password" />
Review comment:
@cheese8 I think this pr is a big change, can we add more test case for this pr?
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
##########
@@ -63,10 +74,22 @@ protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStat
@Override
public Collection<SubstitutableColumnNameToken> generateSQLTokens(final SelectStatementContext selectStatementContext) {
ProjectionsSegment projectionsSegment = selectStatementContext.getSqlStatement().getProjections();
- // TODO process multiple tables
- String tableName = selectStatementContext.getAllTables().iterator().next().getTableName().getIdentifier().getValue();
- return getEncryptRule().findEncryptTable(tableName).map(
- encryptTable -> generateSQLTokens(projectionsSegment, tableName, selectStatementContext, encryptTable)).orElseGet(Collections::emptyList);
+ Collection<SimpleTableSegment> simpleTableSegments = selectStatementContext.getAllTables();
+ Map<String, SimpleTableSegment> tableSegmentMap = selectStatementContext.getTablesContext().getUniqueTables();
+ List<SubstitutableColumnNameToken> substitutableColumnNameTokenList = new ArrayList<>();
+ for (SimpleTableSegment simpleTableSegment : tableSegmentMap.values()) {
+ String tableName = simpleTableSegment.getTableName().getIdentifier().getValue();
+ Optional<EncryptTable> encryptTable = getEncryptRule().findEncryptTable(tableName);
+ if (encryptTable.isPresent()) {
+ Collection<SubstitutableColumnNameToken> sqlTokens = generateSQLTokens(projectionsSegment, tableName, selectStatementContext, encryptTable.get());
+ substitutableColumnNameTokenList.addAll(sqlTokens);
+ }
+ }
+ if (selectStatementContext.isContainsJoinQuery()) {
+ substitutableColumnNameTokenList.addAll(processJoinTableSegments(selectStatementContext, simpleTableSegments));
+ }
+
+ return Collections.unmodifiableList(distinct(substitutableColumnNameTokenList));
Review comment:
@cheese8 Why use `Collections.unmodifiableList`?
##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/ColumnExtractor.java
##########
@@ -54,4 +59,33 @@
}
return Optional.empty();
}
+
+ /**
+ * Get left and right value if either value of expression is column segment.
+ *
+ * @param expression expression segment
+ * @return column segment collection
+ */
+ public static Collection<Optional<ColumnSegment>> extractAll(final ExpressionSegment expression) {
Review comment:
@cheese8 Please use Collection<ColumnSegment> return value.
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptPredicateColumnTokenGenerator.java
##########
@@ -75,38 +78,54 @@ protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStat
private Collection<SubstitutableColumnNameToken> generateSQLTokens(final Collection<ExpressionSegment> predicates, final Map<String, String> columnTableNames) {
Collection<SubstitutableColumnNameToken> result = new LinkedList<>();
for (ExpressionSegment each : predicates) {
- Optional<ColumnSegment> column = ColumnExtractor.extract(each);
- if (!column.isPresent()) {
+ result.addAll(processColumnSegment(ColumnExtractor.extractAll(each), columnTableNames));
+ }
+ return result;
+ }
+
+ private List<SubstitutableColumnNameToken> processColumnSegment(final Collection<Optional<ColumnSegment>> columnSegments, final Map<String, String> columnTableNames) {
+ List<SubstitutableColumnNameToken> result = new LinkedList<>();
+ for (Optional<ColumnSegment> each : columnSegments) {
+ if (!each.isPresent()) {
continue;
}
- Optional<EncryptTable> encryptTable = findEncryptTable(columnTableNames, column.get());
- if (!encryptTable.isPresent() || !encryptTable.get().findEncryptorName(column.get().getIdentifier().getValue()).isPresent()) {
+ Optional<EncryptTable> encryptTable = findEncryptTable(columnTableNames, each.get());
+ if (!encryptTable.isPresent() || !encryptTable.get().findEncryptorName(each.get().getIdentifier().getValue()).isPresent()) {
continue;
}
- int startIndex = column.get().getOwner().isPresent() ? column.get().getOwner().get().getStopIndex() + 2 : column.get().getStartIndex();
- int stopIndex = column.get().getStopIndex();
+ int startIndex = each.get().getOwner().isPresent() ? each.get().getOwner().get().getStopIndex() + 2 : each.get().getStartIndex();
+ int stopIndex = each.get().getStopIndex();
if (!queryWithCipherColumn) {
- Optional<String> plainColumn = encryptTable.get().findPlainColumn(column.get().getIdentifier().getValue());
+ Optional<String> plainColumn = encryptTable.get().findPlainColumn(each.get().getIdentifier().getValue());
if (plainColumn.isPresent()) {
result.add(new SubstitutableColumnNameToken(startIndex, stopIndex, getColumnProjections(plainColumn.get())));
continue;
}
}
- Optional<String> assistedQueryColumn = encryptTable.get().findAssistedQueryColumn(column.get().getIdentifier().getValue());
+ Optional<String> assistedQueryColumn = encryptTable.get().findAssistedQueryColumn(each.get().getIdentifier().getValue());
SubstitutableColumnNameToken encryptColumnNameToken = assistedQueryColumn.map(columnName
-> new SubstitutableColumnNameToken(startIndex, stopIndex, getColumnProjections(columnName))).orElseGet(()
- -> new SubstitutableColumnNameToken(startIndex, stopIndex, getColumnProjections(encryptTable.get().getCipherColumn(column.get().getIdentifier().getValue()))));
+ -> new SubstitutableColumnNameToken(startIndex, stopIndex, getColumnProjections(encryptTable.get().getCipherColumn(each.get().getIdentifier().getValue()))));
result.add(encryptColumnNameToken);
}
return result;
}
private Map<String, String> getColumnTableNames(final SQLStatementContext sqlStatementContext, final Collection<AndPredicate> andPredicates) {
- Collection<ColumnSegment> columns = andPredicates.stream().flatMap(each -> each.getPredicates().stream())
- .map(each -> ColumnExtractor.extract(each).orElse(null)).filter(Objects::nonNull).collect(Collectors.toList());
+ Collection<ColumnSegment> columns = new ArrayList<ColumnSegment>();
Review comment:
@cheese8 Can we use stream api to keep the logic concise?
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
##########
@@ -63,10 +74,22 @@ protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStat
@Override
public Collection<SubstitutableColumnNameToken> generateSQLTokens(final SelectStatementContext selectStatementContext) {
ProjectionsSegment projectionsSegment = selectStatementContext.getSqlStatement().getProjections();
- // TODO process multiple tables
- String tableName = selectStatementContext.getAllTables().iterator().next().getTableName().getIdentifier().getValue();
- return getEncryptRule().findEncryptTable(tableName).map(
- encryptTable -> generateSQLTokens(projectionsSegment, tableName, selectStatementContext, encryptTable)).orElseGet(Collections::emptyList);
+ Collection<SimpleTableSegment> simpleTableSegments = selectStatementContext.getAllTables();
+ Map<String, SimpleTableSegment> tableSegmentMap = selectStatementContext.getTablesContext().getUniqueTables();
+ List<SubstitutableColumnNameToken> substitutableColumnNameTokenList = new ArrayList<>();
+ for (SimpleTableSegment simpleTableSegment : tableSegmentMap.values()) {
+ String tableName = simpleTableSegment.getTableName().getIdentifier().getValue();
Review comment:
If we just want to use tableName, we can invoke `tableContext.getTableNames()` rather than `getTablesContext().getUniqueTables()`.
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
##########
@@ -88,6 +111,71 @@ protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStat
return result;
}
+ private List<SubstitutableColumnNameToken> distinct(final List<SubstitutableColumnNameToken> substitutableColumnNameTokenList) {
Review comment:
@cheese8 Can we use set to remove duplicate data?
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
##########
@@ -88,6 +111,71 @@ protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStat
return result;
}
+ private List<SubstitutableColumnNameToken> distinct(final List<SubstitutableColumnNameToken> substitutableColumnNameTokenList) {
+ Map<String, SubstitutableColumnNameToken> distinctMap = new HashMap<>();
+ for (SubstitutableColumnNameToken each : substitutableColumnNameTokenList) {
+ String key = each.getStartIndex() + "," + each.getStartIndex();
+ if (!distinctMap.containsKey(key)) {
+ distinctMap.put(key, each);
+ }
+ }
+ return new LinkedList<>(distinctMap.values());
+ }
+
+ private Collection<SubstitutableColumnNameToken> processJoinTableSegments(final SelectStatementContext selectStatementContext,
+ final Collection<SimpleTableSegment> simpleTableSegments) {
+ List<SubstitutableColumnNameToken> substitutableColumnNameTokenList = new ArrayList<>();
+ Map<String, String> aliasTable = new HashMap<>(simpleTableSegments.size());
+ for (SimpleTableSegment simpleTableSegment : simpleTableSegments) {
+ String tableName = simpleTableSegment.getTableName().getIdentifier().getValue();
+ String alias = tableName;
+ if (simpleTableSegment.getAlias().isPresent()) {
+ alias = simpleTableSegment.getAlias().get();
+ }
+ aliasTable.put(alias, tableName);
+ }
+ TableSegment tableSegment = selectStatementContext.getSqlStatement().getFrom();
Review comment:
@cheese8 Please use common table extract logic by calling `TableExtractor`.
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptPredicateColumnTokenGenerator.java
##########
@@ -75,38 +78,54 @@ protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStat
private Collection<SubstitutableColumnNameToken> generateSQLTokens(final Collection<ExpressionSegment> predicates, final Map<String, String> columnTableNames) {
Collection<SubstitutableColumnNameToken> result = new LinkedList<>();
for (ExpressionSegment each : predicates) {
- Optional<ColumnSegment> column = ColumnExtractor.extract(each);
- if (!column.isPresent()) {
+ result.addAll(processColumnSegment(ColumnExtractor.extractAll(each), columnTableNames));
+ }
+ return result;
+ }
+
+ private List<SubstitutableColumnNameToken> processColumnSegment(final Collection<Optional<ColumnSegment>> columnSegments, final Map<String, String> columnTableNames) {
+ List<SubstitutableColumnNameToken> result = new LinkedList<>();
Review comment:
@cheese8 If you don't have to use List for operation, the Collection type is better.
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
##########
@@ -63,10 +74,22 @@ protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStat
@Override
public Collection<SubstitutableColumnNameToken> generateSQLTokens(final SelectStatementContext selectStatementContext) {
ProjectionsSegment projectionsSegment = selectStatementContext.getSqlStatement().getProjections();
- // TODO process multiple tables
- String tableName = selectStatementContext.getAllTables().iterator().next().getTableName().getIdentifier().getValue();
- return getEncryptRule().findEncryptTable(tableName).map(
- encryptTable -> generateSQLTokens(projectionsSegment, tableName, selectStatementContext, encryptTable)).orElseGet(Collections::emptyList);
+ Collection<SimpleTableSegment> simpleTableSegments = selectStatementContext.getAllTables();
+ Map<String, SimpleTableSegment> tableSegmentMap = selectStatementContext.getTablesContext().getUniqueTables();
+ List<SubstitutableColumnNameToken> substitutableColumnNameTokenList = new ArrayList<>();
+ for (SimpleTableSegment simpleTableSegment : tableSegmentMap.values()) {
Review comment:
@cheese8 I think `each` is better.
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
##########
@@ -88,6 +111,71 @@ protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStat
return result;
}
+ private List<SubstitutableColumnNameToken> distinct(final List<SubstitutableColumnNameToken> substitutableColumnNameTokenList) {
+ Map<String, SubstitutableColumnNameToken> distinctMap = new HashMap<>();
+ for (SubstitutableColumnNameToken each : substitutableColumnNameTokenList) {
+ String key = each.getStartIndex() + "," + each.getStartIndex();
+ if (!distinctMap.containsKey(key)) {
+ distinctMap.put(key, each);
+ }
+ }
+ return new LinkedList<>(distinctMap.values());
+ }
+
+ private Collection<SubstitutableColumnNameToken> processJoinTableSegments(final SelectStatementContext selectStatementContext,
+ final Collection<SimpleTableSegment> simpleTableSegments) {
+ List<SubstitutableColumnNameToken> substitutableColumnNameTokenList = new ArrayList<>();
+ Map<String, String> aliasTable = new HashMap<>(simpleTableSegments.size());
Review comment:
@cheese8 Can we extract this logic to a private method?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] cheese8 commented on a change in pull request #12504: Support encrypt rewrite for join table segment (SimpleTableSegment)
Posted by GitBox <gi...@apache.org>.
cheese8 commented on a change in pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504#discussion_r711608075
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptPredicateColumnTokenGenerator.java
##########
@@ -75,35 +77,43 @@ protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStat
private Collection<SubstitutableColumnNameToken> generateSQLTokens(final Collection<ExpressionSegment> predicates, final Map<String, String> columnTableNames) {
Collection<SubstitutableColumnNameToken> result = new LinkedList<>();
for (ExpressionSegment each : predicates) {
- Optional<ColumnSegment> column = ColumnExtractor.extract(each);
- if (!column.isPresent()) {
- continue;
- }
- Optional<EncryptTable> encryptTable = findEncryptTable(columnTableNames, column.get());
- if (!encryptTable.isPresent() || !encryptTable.get().findEncryptorName(column.get().getIdentifier().getValue()).isPresent()) {
- continue;
- }
- int startIndex = column.get().getOwner().isPresent() ? column.get().getOwner().get().getStopIndex() + 2 : column.get().getStartIndex();
- int stopIndex = column.get().getStopIndex();
- if (!queryWithCipherColumn) {
- Optional<String> plainColumn = encryptTable.get().findPlainColumn(column.get().getIdentifier().getValue());
- if (plainColumn.isPresent()) {
- result.add(new SubstitutableColumnNameToken(startIndex, stopIndex, getColumnProjections(plainColumn.get())));
+ Collection<Optional<ColumnSegment>> columns = ColumnExtractor.extractAll(each);
+ for (Optional<ColumnSegment> column : columns) {
+ if (!column.isPresent()) {
+ continue;
+ }
+ Optional<EncryptTable> encryptTable = findEncryptTable(columnTableNames, column.get());
+ if (!encryptTable.isPresent() || !encryptTable.get().findEncryptorName(column.get().getIdentifier().getValue()).isPresent()) {
continue;
}
+ int startIndex = column.get().getOwner().isPresent() ? column.get().getOwner().get().getStopIndex() + 2 : column.get().getStartIndex();
+ int stopIndex = column.get().getStopIndex();
+ if (!queryWithCipherColumn) {
+ Optional<String> plainColumn = encryptTable.get().findPlainColumn(column.get().getIdentifier().getValue());
+ if (plainColumn.isPresent()) {
+ result.add(new SubstitutableColumnNameToken(startIndex, stopIndex, getColumnProjections(plainColumn.get())));
+ continue;
+ }
+ }
+ Optional<String> assistedQueryColumn = encryptTable.get().findAssistedQueryColumn(column.get().getIdentifier().getValue());
+ SubstitutableColumnNameToken encryptColumnNameToken = assistedQueryColumn.map(columnName
+ -> new SubstitutableColumnNameToken(startIndex, stopIndex, getColumnProjections(columnName))).orElseGet(()
+ -> new SubstitutableColumnNameToken(startIndex, stopIndex, getColumnProjections(encryptTable.get().getCipherColumn(column.get().getIdentifier().getValue()))));
+ result.add(encryptColumnNameToken);
}
- Optional<String> assistedQueryColumn = encryptTable.get().findAssistedQueryColumn(column.get().getIdentifier().getValue());
- SubstitutableColumnNameToken encryptColumnNameToken = assistedQueryColumn.map(columnName
- -> new SubstitutableColumnNameToken(startIndex, stopIndex, getColumnProjections(columnName))).orElseGet(()
- -> new SubstitutableColumnNameToken(startIndex, stopIndex, getColumnProjections(encryptTable.get().getCipherColumn(column.get().getIdentifier().getValue()))));
- result.add(encryptColumnNameToken);
}
return result;
}
private Map<String, String> getColumnTableNames(final SQLStatementContext sqlStatementContext, final Collection<AndPredicate> andPredicates) {
- Collection<ColumnSegment> columns = andPredicates.stream().flatMap(each -> each.getPredicates().stream())
- .map(each -> ColumnExtractor.extract(each).orElse(null)).filter(Objects::nonNull).collect(Collectors.toList());
+ Collection<ColumnSegment> columns = new ArrayList<ColumnSegment>();
+ for (AndPredicate andPredicate : andPredicates) {
Review comment:
fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] cheese8 commented on a change in pull request #12504: Support encrypt rewrite for join table segment (SimpleTableSegment)
Posted by GitBox <gi...@apache.org>.
cheese8 commented on a change in pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504#discussion_r716137627
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
##########
@@ -63,10 +75,19 @@ protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStat
@Override
public Collection<SubstitutableColumnNameToken> generateSQLTokens(final SelectStatementContext selectStatementContext) {
ProjectionsSegment projectionsSegment = selectStatementContext.getSqlStatement().getProjections();
- // TODO process multiple tables
- String tableName = selectStatementContext.getAllTables().iterator().next().getTableName().getIdentifier().getValue();
- return getEncryptRule().findEncryptTable(tableName).map(
- encryptTable -> generateSQLTokens(projectionsSegment, tableName, selectStatementContext, encryptTable)).orElseGet(Collections::emptyList);
+ Collection<SubstitutableColumnNameToken> result = new HashSet<>();
+ Collection<String> tableNames = selectStatementContext.getTablesContext().getTableNames();
+ for (String each : tableNames) {
+ Optional<EncryptTable> encryptTable = getEncryptRule().findEncryptTable(each);
+ if (encryptTable.isPresent()) {
+ Collection<SubstitutableColumnNameToken> sqlTokens = generateSQLTokens(projectionsSegment, each, selectStatementContext, encryptTable.get());
+ result.addAll(sqlTokens);
+ }
+ }
+ if (selectStatementContext.isContainsJoinQuery()) {
Review comment:
changed and fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] strongduanmu merged pull request #12504: Support encrypt rewrite for join table segment (SimpleTableSegment)
Posted by GitBox <gi...@apache.org>.
strongduanmu merged pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] codecov-commenter edited a comment on pull request #12504: Support encrypt rewrite for join table segment (SimpleTableSegment)
Posted by GitBox <gi...@apache.org>.
codecov-commenter edited a comment on pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504#issuecomment-921926307
# [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#12504](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (fdc1cac) into [master](https://codecov.io/gh/apache/shardingsphere/commit/09741b92e875f7d04fa38f5f9bb5898a2a70c567?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (09741b9) will **decrease** coverage by `0.39%`.
> The diff coverage is `22.52%`.
[![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/12504/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
```diff
@@ Coverage Diff @@
## master #12504 +/- ##
============================================
- Coverage 63.59% 63.19% -0.40%
- Complexity 1303 1347 +44
============================================
Files 2394 2474 +80
Lines 36430 37400 +970
Branches 6320 6450 +130
============================================
+ Hits 23168 23636 +468
- Misses 11388 11846 +458
- Partials 1874 1918 +44
```
| [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [...rypt/rewrite/condition/EncryptConditionEngine.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS9jb25kaXRpb24vRW5jcnlwdENvbmRpdGlvbkVuZ2luZS5qYXZh) | `0.00% <0.00%> (ø)` | |
| [...meter/impl/EncryptAssignmentParameterRewriter.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS9wYXJhbWV0ZXIvaW1wbC9FbmNyeXB0QXNzaWdubWVudFBhcmFtZXRlclJld3JpdGVyLmphdmE=) | `0.00% <0.00%> (ø)` | |
| [...ertOnDuplicateKeyUpdateValueParameterRewriter.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS9wYXJhbWV0ZXIvaW1wbC9FbmNyeXB0SW5zZXJ0T25EdXBsaWNhdGVLZXlVcGRhdGVWYWx1ZVBhcmFtZXRlclJld3JpdGVyLmphdmE=) | `0.00% <0.00%> (ø)` | |
| [...eter/impl/EncryptInsertValueParameterRewriter.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS9wYXJhbWV0ZXIvaW1wbC9FbmNyeXB0SW5zZXJ0VmFsdWVQYXJhbWV0ZXJSZXdyaXRlci5qYXZh) | `0.00% <0.00%> (ø)` | |
| [...ameter/impl/EncryptPredicateParameterRewriter.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS9wYXJhbWV0ZXIvaW1wbC9FbmNyeXB0UHJlZGljYXRlUGFyYW1ldGVyUmV3cml0ZXIuamF2YQ==) | `0.00% <0.00%> (ø)` | |
| [...enerator/impl/EncryptAssignmentTokenGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS90b2tlbi9nZW5lcmF0b3IvaW1wbC9FbmNyeXB0QXNzaWdubWVudFRva2VuR2VuZXJhdG9yLmphdmE=) | `0.00% <0.00%> (ø)` | |
| [...ator/impl/EncryptInsertOnUpdateTokenGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS90b2tlbi9nZW5lcmF0b3IvaW1wbC9FbmNyeXB0SW5zZXJ0T25VcGRhdGVUb2tlbkdlbmVyYXRvci5qYXZh) | `0.00% <0.00%> (ø)` | |
| [...erator/impl/EncryptInsertValuesTokenGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS90b2tlbi9nZW5lcmF0b3IvaW1wbC9FbmNyeXB0SW5zZXJ0VmFsdWVzVG9rZW5HZW5lcmF0b3IuamF2YQ==) | `0.00% <0.00%> (ø)` | |
| [...tor/impl/EncryptPredicateColumnTokenGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS90b2tlbi9nZW5lcmF0b3IvaW1wbC9FbmNyeXB0UHJlZGljYXRlQ29sdW1uVG9rZW5HZW5lcmF0b3IuamF2YQ==) | `0.00% <0.00%> (ø)` | |
| [...impl/EncryptPredicateRightValueTokenGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS90b2tlbi9nZW5lcmF0b3IvaW1wbC9FbmNyeXB0UHJlZGljYXRlUmlnaHRWYWx1ZVRva2VuR2VuZXJhdG9yLmphdmE=) | `0.00% <0.00%> (ø)` | |
| ... and [405 more](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [c1c878a...fdc1cac](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] cheese8 commented on a change in pull request #12504: Support encrypt rewrite for join table segment (SimpleTableSegment)
Posted by GitBox <gi...@apache.org>.
cheese8 commented on a change in pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504#discussion_r711608127
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
##########
@@ -88,6 +111,90 @@ protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStat
return result;
}
+ private Map<String, SimpleTableSegment> distinct(final Collection<SimpleTableSegment> simpleTableSegments) {
Review comment:
yes, thanks for hints
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] cheese8 commented on a change in pull request #12504: Support encrypt rewrite for join table segment (SimpleTableSegment)
Posted by GitBox <gi...@apache.org>.
cheese8 commented on a change in pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504#discussion_r717321565
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptPredicateColumnTokenGenerator.java
##########
@@ -56,57 +59,82 @@
@Override
protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStatementContext) {
+ return isGenerateSQLTokenForEncryptOnWhereAvailable(sqlStatementContext) || isGenerateSQLTokenForEncryptOnJoinSegments(sqlStatementContext);
+ }
+
+ private boolean isGenerateSQLTokenForEncryptOnWhereAvailable(final SQLStatementContext sqlStatementContext) {
return sqlStatementContext instanceof WhereAvailable && ((WhereAvailable) sqlStatementContext).getWhere().isPresent();
}
+ private boolean isGenerateSQLTokenForEncryptOnJoinSegments(final SQLStatementContext sqlStatementContext) {
+ return sqlStatementContext instanceof SelectStatementContext && !WhereExtractUtil.getJoinWhereSegments((SelectStatement) sqlStatementContext.getSqlStatement()).isEmpty();
+ }
+
@Override
public Collection<SubstitutableColumnNameToken> generateSQLTokens(final SQLStatementContext sqlStatementContext) {
- Preconditions.checkState(((WhereAvailable) sqlStatementContext).getWhere().isPresent());
Collection<SubstitutableColumnNameToken> result = new LinkedHashSet<>();
- ExpressionSegment expression = ((WhereAvailable) sqlStatementContext).getWhere().get().getExpr();
- Collection<AndPredicate> andPredicates = ExpressionExtractUtil.getAndPredicates(expression);
- Map<String, String> columnTableNames = getColumnTableNames(sqlStatementContext, andPredicates);
- for (AndPredicate each : andPredicates) {
- result.addAll(generateSQLTokens(each.getPredicates(), columnTableNames));
+ Collection<AndPredicate> andPredicates = new LinkedHashSet<>();
+ if (isGenerateSQLTokenForEncryptOnWhereAvailable(sqlStatementContext)) {
+ ExpressionSegment expression = ((WhereAvailable) sqlStatementContext).getWhere().get().getExpr();
+ andPredicates.addAll(ExpressionExtractUtil.getAndPredicates(expression));
}
+ Optional<Collection<WhereSegment>> whereSegments = Optional.empty();
+ if (sqlStatementContext instanceof SelectStatementContext) {
+ whereSegments = Optional.of(WhereExtractUtil.getJoinWhereSegments((SelectStatement) sqlStatementContext.getSqlStatement()));
Review comment:
fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] codecov-commenter commented on pull request #12504: Support encrypt rewrite for join table segment (SimpleTableSegment)
Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504#issuecomment-921926307
# [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#12504](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (3545a01) into [master](https://codecov.io/gh/apache/shardingsphere/commit/09741b92e875f7d04fa38f5f9bb5898a2a70c567?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (09741b9) will **decrease** coverage by `0.25%`.
> The diff coverage is `13.83%`.
[![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/12504/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
```diff
@@ Coverage Diff @@
## master #12504 +/- ##
============================================
- Coverage 63.59% 63.34% -0.26%
Complexity 1303 1303
============================================
Files 2394 2408 +14
Lines 36430 36756 +326
Branches 6320 6387 +67
============================================
+ Hits 23168 23282 +114
- Misses 11388 11586 +198
- Partials 1874 1888 +14
```
| [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [...rypt/rewrite/condition/EncryptConditionEngine.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS9jb25kaXRpb24vRW5jcnlwdENvbmRpdGlvbkVuZ2luZS5qYXZh) | `0.00% <0.00%> (ø)` | |
| [...meter/impl/EncryptAssignmentParameterRewriter.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS9wYXJhbWV0ZXIvaW1wbC9FbmNyeXB0QXNzaWdubWVudFBhcmFtZXRlclJld3JpdGVyLmphdmE=) | `0.00% <0.00%> (ø)` | |
| [...ertOnDuplicateKeyUpdateValueParameterRewriter.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS9wYXJhbWV0ZXIvaW1wbC9FbmNyeXB0SW5zZXJ0T25EdXBsaWNhdGVLZXlVcGRhdGVWYWx1ZVBhcmFtZXRlclJld3JpdGVyLmphdmE=) | `0.00% <0.00%> (ø)` | |
| [...eter/impl/EncryptInsertValueParameterRewriter.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS9wYXJhbWV0ZXIvaW1wbC9FbmNyeXB0SW5zZXJ0VmFsdWVQYXJhbWV0ZXJSZXdyaXRlci5qYXZh) | `0.00% <0.00%> (ø)` | |
| [...ameter/impl/EncryptPredicateParameterRewriter.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS9wYXJhbWV0ZXIvaW1wbC9FbmNyeXB0UHJlZGljYXRlUGFyYW1ldGVyUmV3cml0ZXIuamF2YQ==) | `0.00% <0.00%> (ø)` | |
| [...enerator/impl/EncryptAssignmentTokenGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS90b2tlbi9nZW5lcmF0b3IvaW1wbC9FbmNyeXB0QXNzaWdubWVudFRva2VuR2VuZXJhdG9yLmphdmE=) | `0.00% <0.00%> (ø)` | |
| [...ator/impl/EncryptInsertOnUpdateTokenGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS90b2tlbi9nZW5lcmF0b3IvaW1wbC9FbmNyeXB0SW5zZXJ0T25VcGRhdGVUb2tlbkdlbmVyYXRvci5qYXZh) | `0.00% <0.00%> (ø)` | |
| [...erator/impl/EncryptInsertValuesTokenGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS90b2tlbi9nZW5lcmF0b3IvaW1wbC9FbmNyeXB0SW5zZXJ0VmFsdWVzVG9rZW5HZW5lcmF0b3IuamF2YQ==) | `0.00% <0.00%> (ø)` | |
| [...tor/impl/EncryptPredicateColumnTokenGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS90b2tlbi9nZW5lcmF0b3IvaW1wbC9FbmNyeXB0UHJlZGljYXRlQ29sdW1uVG9rZW5HZW5lcmF0b3IuamF2YQ==) | `0.00% <0.00%> (ø)` | |
| [...impl/EncryptPredicateRightValueTokenGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS90b2tlbi9nZW5lcmF0b3IvaW1wbC9FbmNyeXB0UHJlZGljYXRlUmlnaHRWYWx1ZVRva2VuR2VuZXJhdG9yLmphdmE=) | `0.00% <0.00%> (ø)` | |
| ... and [123 more](https://codecov.io/gh/apache/shardingsphere/pull/12504/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [c1c878a...3545a01](https://codecov.io/gh/apache/shardingsphere/pull/12504?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] cheese8 commented on a change in pull request #12504: Support encrypt rewrite for join table segment (SimpleTableSegment)
Posted by GitBox <gi...@apache.org>.
cheese8 commented on a change in pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504#discussion_r716136953
##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/TableExtractor.java
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+
+package org.apache.shardingsphere.sql.parser.sql.common.util;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Table extractor.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class TableExtractor {
Review comment:
fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] cheese8 commented on a change in pull request #12504: Support encrypt rewrite for join table segment (SimpleTableSegment)
Posted by GitBox <gi...@apache.org>.
cheese8 commented on a change in pull request #12504:
URL: https://github.com/apache/shardingsphere/pull/12504#discussion_r717321396
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptPredicateColumnTokenGenerator.java
##########
@@ -56,57 +59,82 @@
@Override
protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStatementContext) {
+ return isGenerateSQLTokenForEncryptOnWhereAvailable(sqlStatementContext) || isGenerateSQLTokenForEncryptOnJoinSegments(sqlStatementContext);
+ }
+
+ private boolean isGenerateSQLTokenForEncryptOnWhereAvailable(final SQLStatementContext sqlStatementContext) {
return sqlStatementContext instanceof WhereAvailable && ((WhereAvailable) sqlStatementContext).getWhere().isPresent();
}
+ private boolean isGenerateSQLTokenForEncryptOnJoinSegments(final SQLStatementContext sqlStatementContext) {
+ return sqlStatementContext instanceof SelectStatementContext && !WhereExtractUtil.getJoinWhereSegments((SelectStatement) sqlStatementContext.getSqlStatement()).isEmpty();
Review comment:
fixed
##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptPredicateColumnTokenGenerator.java
##########
@@ -56,57 +59,82 @@
@Override
protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext sqlStatementContext) {
+ return isGenerateSQLTokenForEncryptOnWhereAvailable(sqlStatementContext) || isGenerateSQLTokenForEncryptOnJoinSegments(sqlStatementContext);
+ }
+
+ private boolean isGenerateSQLTokenForEncryptOnWhereAvailable(final SQLStatementContext sqlStatementContext) {
return sqlStatementContext instanceof WhereAvailable && ((WhereAvailable) sqlStatementContext).getWhere().isPresent();
}
+ private boolean isGenerateSQLTokenForEncryptOnJoinSegments(final SQLStatementContext sqlStatementContext) {
+ return sqlStatementContext instanceof SelectStatementContext && !WhereExtractUtil.getJoinWhereSegments((SelectStatement) sqlStatementContext.getSqlStatement()).isEmpty();
+ }
+
@Override
public Collection<SubstitutableColumnNameToken> generateSQLTokens(final SQLStatementContext sqlStatementContext) {
- Preconditions.checkState(((WhereAvailable) sqlStatementContext).getWhere().isPresent());
Collection<SubstitutableColumnNameToken> result = new LinkedHashSet<>();
- ExpressionSegment expression = ((WhereAvailable) sqlStatementContext).getWhere().get().getExpr();
- Collection<AndPredicate> andPredicates = ExpressionExtractUtil.getAndPredicates(expression);
- Map<String, String> columnTableNames = getColumnTableNames(sqlStatementContext, andPredicates);
- for (AndPredicate each : andPredicates) {
- result.addAll(generateSQLTokens(each.getPredicates(), columnTableNames));
+ Collection<AndPredicate> andPredicates = new LinkedHashSet<>();
+ if (isGenerateSQLTokenForEncryptOnWhereAvailable(sqlStatementContext)) {
+ ExpressionSegment expression = ((WhereAvailable) sqlStatementContext).getWhere().get().getExpr();
+ andPredicates.addAll(ExpressionExtractUtil.getAndPredicates(expression));
}
+ Optional<Collection<WhereSegment>> whereSegments = Optional.empty();
+ if (sqlStatementContext instanceof SelectStatementContext) {
+ whereSegments = Optional.of(WhereExtractUtil.getJoinWhereSegments((SelectStatement) sqlStatementContext.getSqlStatement()));
Review comment:
fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org