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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]