This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new c067313a29c Add EncryptColumnAlterException (#20345)
c067313a29c is described below

commit c067313a29ca0400952065dc0b6c7a170852a181
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Aug 22 11:09:26 2022 +0800

    Add EncryptColumnAlterException (#20345)
---
 .../user-manual/error-code/sql-error-code.cn.md    |  1 +
 .../user-manual/error-code/sql-error-code.en.md    |  1 +
 .../exception/EncryptColumnAlterException.java     | 33 ++++++++++++++++++++++
 .../generator/EncryptAlterTableTokenGenerator.java |  4 +--
 4 files changed, 37 insertions(+), 2 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 59cfa0fc3f0..493bb92362f 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
@@ -25,5 +25,6 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | HY000     | 16001       | Failed to get DDL for table \`%s\` |
 | HY004     | 24000       | Encrypt algorithm \`%s\` initialize failed, reason 
is: %s |
 | HY004     | 24001       | The SQL clause \`%s\` is unsupported in encrypt 
rule |
+| 44000     | 24002       | Altered column \`%s\` must use same encrypt 
algorithm with previous column \`%s\` in table \`%s\` |
 | HY004     | 25000       | Shadow column \`%s\` of table \`%s\` does not 
support \`%s\` type |
 | 42000     | 30000       | Unknown exception: %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 a5e0e008814..161dc4f16b4 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
@@ -25,5 +25,6 @@ SQL error codes provide by standard `SQL State`, `Vendor 
Code` and `Reason`, whi
 | HY000     | 16001       | Failed to get DDL for table \`%s\` |
 | HY004     | 24000       | Encrypt algorithm \`%s\` initialize failed, reason 
is: %s |
 | HY004     | 24001       | The SQL clause \`%s\` is unsupported in encrypt 
rule |
+| 44000     | 24002       | Altered column \`%s\` must use same encrypt 
algorithm with previous column \`%s\` in table \`%s\` |
 | HY004     | 25000       | Shadow column \`%s\` of table \`%s\` does not 
support \`%s\` type |
 | 42000     | 30000       | Unknown exception: %s |
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/exception/EncryptColumnAlterException.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/exception/EncryptColumnAlterException.java
new file mode 100644
index 00000000000..a62c687e07f
--- /dev/null
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/exception/EncryptColumnAlterException.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;
+
+import 
org.apache.shardingsphere.infra.util.exception.sql.ShardingSphereSQLException;
+import 
org.apache.shardingsphere.infra.util.exception.sql.sqlstate.XOpenSQLState;
+
+/**
+ * Encrypt column alter exception.
+ */
+public final class EncryptColumnAlterException extends 
ShardingSphereSQLException {
+    
+    private static final long serialVersionUID = -8920381230872401155L;
+    
+    public EncryptColumnAlterException(final String table, final String 
alteredColumn, final String previousColumn) {
+        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 24002, "Altered column 
`%s` must use same encrypt algorithm with previous column `%s` in table `%s`", 
alteredColumn, previousColumn, table);
+    }
+}
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGenerator.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGenerator.java
index 2f319e779e4..d6f85c9ccee 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGenerator.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGenerator.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.encrypt.rewrite.token.generator;
 
 import lombok.Setter;
+import org.apache.shardingsphere.encrypt.exception.EncryptColumnAlterException;
 import 
org.apache.shardingsphere.encrypt.rewrite.token.pojo.EncryptAlterTableToken;
 import org.apache.shardingsphere.encrypt.rule.EncryptColumn;
 import org.apache.shardingsphere.encrypt.rule.EncryptRule;
@@ -26,7 +27,6 @@ import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
 import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
 import 
org.apache.shardingsphere.infra.binder.statement.ddl.AlterTableStatementContext;
 import 
org.apache.shardingsphere.infra.config.exception.ShardingSphereConfigurationException;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
 import 
org.apache.shardingsphere.infra.rewrite.sql.token.generator.CollectionSQLTokenGenerator;
 import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
 import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.Substitutable;
@@ -226,7 +226,7 @@ public final class EncryptAlterTableTokenGenerator 
implements CollectionSQLToken
                 return;
             }
         }
-        throw new ShardingSphereException("Alter change column statement's 
columns must both have same encrypt algorithm!");
+        throw new EncryptColumnAlterException(tableName, 
segment.getColumnDefinition().getColumnName().getIdentifier().getValue(), 
segment.getPreviousColumn().getIdentifier().getValue());
     }
     
     private boolean checkPreviousAndAfterHasSameColumnNumber(final String 
tableName, final ChangeColumnDefinitionSegment segment) {

Reply via email to