Skip to content

Commit

Permalink
Fix lower case like query error in PG. (apache#23771)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuichenchuxin authored Jan 28, 2023
1 parent 70c02a3 commit 3917755
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
import org.apache.shardingsphere.encrypt.exception.syntax.UnsupportedEncryptSQLException;
import org.apache.shardingsphere.encrypt.rewrite.aware.DatabaseNameAware;
import org.apache.shardingsphere.encrypt.rewrite.aware.EncryptConditionsAware;
import org.apache.shardingsphere.encrypt.rewrite.aware.EncryptRuleAware;
import org.apache.shardingsphere.encrypt.rewrite.condition.EncryptCondition;
import org.apache.shardingsphere.encrypt.rewrite.condition.impl.EncryptBinaryCondition;
import org.apache.shardingsphere.encrypt.rewrite.condition.impl.EncryptInCondition;
import org.apache.shardingsphere.encrypt.rewrite.token.pojo.EncryptPredicateEqualRightValueToken;
import org.apache.shardingsphere.encrypt.rewrite.token.pojo.EncryptPredicateInRightValueToken;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.rewrite.aware.EncryptRuleAware;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.type.WhereAvailable;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
Expand Down Expand Up @@ -96,7 +96,7 @@ private SQLToken generateSQLTokenForQueryWithCipherColumn(final String schemaNam
}

private List<Object> getEncryptedValues(final String schemaName, final EncryptCondition encryptCondition, final List<Object> originalValues) {
if (encryptCondition instanceof EncryptBinaryCondition && "LIKE".equals(((EncryptBinaryCondition) encryptCondition).getOperator())) {
if (encryptCondition instanceof EncryptBinaryCondition && "LIKE".equalsIgnoreCase(((EncryptBinaryCondition) encryptCondition).getOperator())) {
Optional<String> likeQueryColumn = encryptRule.findLikeQueryColumn(encryptCondition.getTableName(), encryptCondition.getColumnName());
if (!likeQueryColumn.isPresent()) {
throw new UnsupportedEncryptSQLException("LIKE");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,11 @@
<assertion expected-data-source-name="read_dataset" />
</test-case>

<test-case sql="SELECT * FROM t_merchant WHERE business_code like '%18'" db-types="MySQL,PostgreSQL,openGauss" scenario-types="db,encrypt"
scenario-comments="Test single table's lower case like operator percentage wildcard in simple select statement when use sharding feature.|Test encrypt table's lower case like operator percentage wildcard in simple select statement when use encrypt feature.">
<assertion expected-data-source-name="read_dataset" />
</test-case>

<test-case sql="SELECT * FROM t_merchant WHERE business_code LIKE '_1000018'" db-types="MySQL,PostgreSQL,openGauss" scenario-types="db,encrypt"
scenario-comments="Test single table's LIKE operator underscore wildcard in simple select statement when use sharding feature.|Test encrypt table's LIKE operator underscore wildcard in simple select statement when use encrypt feature.">
<assertion expected-data-source-name="read_dataset" />
Expand Down

0 comments on commit 3917755

Please sign in to comment.