This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new b3cecf7f84d Add MissingMatchedEncryptQueryAlgorithmException (#32379)
b3cecf7f84d is described below
commit b3cecf7f84d7958241a9c3b40e19fade6fe34d65
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Aug 3 16:17:05 2024 +0800
Add MissingMatchedEncryptQueryAlgorithmException (#32379)
---
.../user-manual/error-code/sql-error-code.cn.md | 1 +
.../user-manual/error-code/sql-error-code.en.md | 1 +
...ssingMatchedEncryptQueryAlgorithmException.java | 33 ++++++++++++++++++++++
.../EncryptPredicateColumnTokenGenerator.java | 13 +++++----
4 files changed, 42 insertions(+), 6 deletions(-)
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
index 9f3990fdf3b..e83b60ba036 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
@@ -226,6 +226,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| 21002 | 42S02 | Can not find logic encrypt column by '%s'.
|
| 21003 | 42S02 | Can not find encrypt column '%s' from table '%s'.
|
| 21004 | HY000 | '%s' column's encrypt algorithm '%s' should
support %s in database '%s'. |
+| 21005 | HY000 | Column '%s' of table '%s' is not configured with
%s query algorithm. |
| 21010 | 44000 | Altered column '%s' must use same encrypt
algorithm with previous column '%s' in table '%s'. |
| 21020 | 0A000 | The SQL clause '%s' is unsupported in encrypt
feature. |
| 21030 | 22000 | Failed to decrypt the ciphertext '%s' in the
column '%s' of table '%s'. |
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.en.md
b/docs/document/content/user-manual/error-code/sql-error-code.en.md
index 36f50139c9f..88f2cca1754 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.en.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.en.md
@@ -226,6 +226,7 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| 21002 | 42S02 | Can not find logic encrypt column by '%s'.
|
| 21003 | 42S02 | Can not find encrypt column '%s' from table '%s'.
|
| 21004 | HY000 | '%s' column's encrypt algorithm '%s' should
support %s in database '%s'. |
+| 21005 | HY000 | Column '%s' of table '%s' is not configured with
%s query algorithm. |
| 21010 | 44000 | Altered column '%s' must use same encrypt
algorithm with previous column '%s' in table '%s'. |
| 21020 | 0A000 | The SQL clause '%s' is unsupported in encrypt
feature. |
| 21030 | 22000 | Failed to decrypt the ciphertext '%s' in the
column '%s' of table '%s'. |
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/exception/metadata/MissingMatchedEncryptQueryAlgorithmException.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/exception/metadata/MissingMatchedEncryptQueryAlgorithmException.java
new file mode 100644
index 00000000000..de5ca8f8069
--- /dev/null
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/exception/metadata/MissingMatchedEncryptQueryAlgorithmException.java
@@ -0,0 +1,33 @@
+/*
+ * 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.encrypt.exception.metadata;
+
+import org.apache.shardingsphere.encrypt.exception.EncryptSQLException;
+import
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
+
+/**
+ * Missing matched encrypt query algorithm exception.
+ */
+public final class MissingMatchedEncryptQueryAlgorithmException extends
EncryptSQLException {
+
+ private static final long serialVersionUID = 6863015760524780348L;
+
+ public MissingMatchedEncryptQueryAlgorithmException(final String table,
final String column, final String type) {
+ super(XOpenSQLState.GENERAL_ERROR, 5, "Column '%s' of table '%s' is
not configured with %s query algorithm.", column, table, type);
+ }
+}
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateColumnTokenGenerator.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateColumnTokenGenerator.java
index d3a94f72ea6..2770b4be3c6 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateColumnTokenGenerator.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateColumnTokenGenerator.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.encrypt.rewrite.token.generator.predicate;
import lombok.Setter;
-import
org.apache.shardingsphere.encrypt.exception.syntax.UnsupportedEncryptSQLException;
+import
org.apache.shardingsphere.encrypt.exception.metadata.MissingMatchedEncryptQueryAlgorithmException;
import org.apache.shardingsphere.encrypt.rewrite.aware.EncryptRuleAware;
import
org.apache.shardingsphere.encrypt.rewrite.token.comparator.JoinConditionsEncryptorComparator;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
@@ -85,25 +85,26 @@ public final class EncryptPredicateColumnTokenGenerator
implements CollectionSQL
return generateSQLTokens(columnSegments, columnExpressionTableNames,
whereSegments, sqlStatementContext.getDatabaseType());
}
- private Collection<SQLToken> generateSQLTokens(final
Collection<ColumnSegment> columnSegments,
- final Map<String, String>
columnExpressionTableNames, final Collection<WhereSegment> whereSegments, final
DatabaseType databaseType) {
+ private Collection<SQLToken> generateSQLTokens(final
Collection<ColumnSegment> columnSegments, final Map<String, String>
columnExpressionTableNames,
+ final
Collection<WhereSegment> whereSegments, final DatabaseType databaseType) {
Collection<SQLToken> result = new
LinkedHashSet<>(columnSegments.size(), 1F);
for (ColumnSegment each : columnSegments) {
String tableName =
columnExpressionTableNames.getOrDefault(each.getExpression(), "");
Optional<EncryptTable> encryptTable =
encryptRule.findEncryptTable(tableName);
if (encryptTable.isPresent() &&
encryptTable.get().isEncryptColumn(each.getIdentifier().getValue())) {
-
result.add(buildSubstitutableColumnNameToken(encryptTable.get().getEncryptColumn(each.getIdentifier().getValue()),
each, whereSegments, databaseType));
+
result.add(buildSubstitutableColumnNameToken(encryptTable.get().getTable(),
encryptTable.get().getEncryptColumn(each.getIdentifier().getValue()), each,
whereSegments, databaseType));
}
}
return result;
}
- private SubstitutableColumnNameToken
buildSubstitutableColumnNameToken(final EncryptColumn encryptColumn,
+ private SubstitutableColumnNameToken
buildSubstitutableColumnNameToken(final String tableName, final EncryptColumn
encryptColumn,
final ColumnSegment columnSegment, final Collection<WhereSegment>
whereSegments, final DatabaseType databaseType) {
int startIndex = columnSegment.getOwner().isPresent() ?
columnSegment.getOwner().get().getStopIndex() + 2 :
columnSegment.getStartIndex();
int stopIndex = columnSegment.getStopIndex();
if (includesLike(whereSegments, columnSegment)) {
- LikeQueryColumnItem likeQueryColumnItem =
encryptColumn.getLikeQuery().orElseThrow(() -> new
UnsupportedEncryptSQLException("LIKE"));
+ LikeQueryColumnItem likeQueryColumnItem =
encryptColumn.getLikeQuery().orElseThrow(
+ () -> new
MissingMatchedEncryptQueryAlgorithmException(tableName,
columnSegment.getIdentifier().getValue(), "LIKE"));
return new SubstitutableColumnNameToken(
startIndex, stopIndex,
createColumnProjections(likeQueryColumnItem.getName(),
columnSegment.getIdentifier().getQuoteCharacter(), databaseType), databaseType);
}