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

yx9o 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 aade53fb27d Add UnsupportedCreateViewException (#20577)
aade53fb27d is described below

commit aade53fb27d9fda9a3cd5402504cd4826ef82f0c
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Aug 26 23:24:23 2022 +0800

    Add UnsupportedCreateViewException (#20577)
---
 .../user-manual/error-code/sql-error-code.cn.md    |  1 +
 .../user-manual/error-code/sql-error-code.en.md    |  1 +
 .../exception/UnsupportedCreateViewException.java  | 33 ++++++++++++++++++++++
 .../impl/ShardingCreateViewStatementValidator.java |  4 +--
 .../ShardingCreateViewStatementValidatorTest.java  |  8 +++---
 5 files changed, 41 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 69bf13b1def..a7d0de036a9 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
@@ -46,6 +46,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | 42S02     | 20008       | Can not get route result, please check your 
sharding rule configuration |
 | 42S01     | 20009       | View name has to bind to %s tables |
 | 0A000     | 20010       | Can not support DML operation with multiple tables 
\`%s\` |
+| 0A000     | 20011       | The CREATE VIEW statement contains unsupported 
query statement |
 | 44000     | 20012       | Inline sharding algorithms expression \`%s\` and 
sharding column \`%s\` are not match |
 | HY004     | 20013       | Found different types for sharding value \`%s\` |
 | HY004     | 24000       | Encrypt algorithm \`%s\` initialize failed, reason 
is: %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 891244867ed..01ab9d3457d 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
@@ -46,6 +46,7 @@ SQL error codes provide by standard `SQL State`, `Vendor 
Code` and `Reason`, whi
 | 42S02     | 20008       | Can not get route result, please check your 
sharding rule configuration |
 | 42S01     | 20009       | View name has to bind to %s tables |
 | 0A000     | 20010       | Can not support DML operation with multiple tables 
\`%s\` |
+| 0A000     | 20011       | The CREATE VIEW statement contains unsupported 
query statement |
 | 44000     | 20012       | Inline sharding algorithms expression \`%s\` and 
sharding column \`%s\` are not match |
 | HY004     | 20013       | Found different types for sharding value \`%s\` |
 | HY004     | 24000       | Encrypt algorithm \`%s\` initialize failed, reason 
is: %s |
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/UnsupportedCreateViewException.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/UnsupportedCreateViewException.java
new file mode 100644
index 00000000000..749fcfb5619
--- /dev/null
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/UnsupportedCreateViewException.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.sharding.exception;
+
+import 
org.apache.shardingsphere.infra.util.exception.sql.ShardingSphereSQLException;
+import 
org.apache.shardingsphere.infra.util.exception.sql.sqlstate.XOpenSQLState;
+
+/**
+ * Unsupported create view exception.
+ */
+public final class UnsupportedCreateViewException extends 
ShardingSphereSQLException {
+    
+    private static final long serialVersionUID = -321126834428609310L;
+    
+    public UnsupportedCreateViewException() {
+        super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 20004, "The CREATE VIEW 
statement contains unsupported query statement");
+    }
+}
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateViewStatementValidator.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateViewStatementValidator.java
index 587a2c9bc5b..1c36adf0d71 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateViewStatementValidator.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateViewStatementValidator.java
@@ -19,10 +19,10 @@ package 
org.apache.shardingsphere.sharding.route.engine.validator.ddl.impl;
 
 import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
 import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.route.context.RouteContext;
 import org.apache.shardingsphere.sharding.exception.EngagedViewException;
+import 
org.apache.shardingsphere.sharding.exception.UnsupportedCreateViewException;
 import 
org.apache.shardingsphere.sharding.route.engine.validator.ddl.ShardingDDLStatementValidator;
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
 import 
org.apache.shardingsphere.sql.parser.sql.common.extractor.TableExtractor;
@@ -70,7 +70,7 @@ public final class ShardingCreateViewStatementValidator 
extends ShardingDDLState
             return;
         }
         if (isContainsNotSupportedViewStatement(selectStatement.get(), 
routeContext)) {
-            throw new ShardingSphereException("This view statement contains 
not supported query statement!");
+            throw new UnsupportedCreateViewException();
         }
     }
     
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateViewStatementValidatorTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateViewStatementValidatorTest.java
index 21e44370322..780551c3217 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateViewStatementValidatorTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateViewStatementValidatorTest.java
@@ -19,10 +19,10 @@ package 
org.apache.shardingsphere.sharding.route.engine.validator.ddl;
 
 import 
org.apache.shardingsphere.infra.binder.statement.ddl.CreateViewStatementContext;
 import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.route.context.RouteContext;
 import org.apache.shardingsphere.sharding.exception.EngagedViewException;
+import 
org.apache.shardingsphere.sharding.exception.UnsupportedCreateViewException;
 import 
org.apache.shardingsphere.sharding.route.engine.validator.ddl.impl.ShardingCreateViewStatementValidator;
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
@@ -94,13 +94,13 @@ public final class ShardingCreateViewStatementValidatorTest 
{
                 mock(ConfigurationProperties.class), routeContext);
     }
     
-    @Test(expected = ShardingSphereException.class)
+    @Test(expected = UnsupportedCreateViewException.class)
     public void assertPostValidateCreateViewWithException() {
         ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
         when(projectionsSegment.isDistinctRow()).thenReturn(true);
         when(selectStatement.getProjections()).thenReturn(projectionsSegment);
-        new ShardingCreateViewStatementValidator().postValidate(shardingRule, 
createViewStatementContext, Collections.emptyList(), 
mock(ShardingSphereDatabase.class),
-                mock(ConfigurationProperties.class), routeContext);
+        new ShardingCreateViewStatementValidator().postValidate(
+                shardingRule, createViewStatementContext, 
Collections.emptyList(), mock(ShardingSphereDatabase.class), 
mock(ConfigurationProperties.class), routeContext);
     }
     
     @Test(expected = EngagedViewException.class)

Reply via email to