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

tuichenchuxin 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 29e067838e5 Add NotImplementComparableValueException, 
InvalidBindingTablesException to handle related exceptions (#23369)
29e067838e5 is described below

commit 29e067838e56bd5bb08579af6aff77258b274a81
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Fri Jan 6 15:14:00 2023 +0800

    Add NotImplementComparableValueException, InvalidBindingTablesException to 
handle related exceptions (#23369)
    
    * Add NotImplementComparableShardingValueException to handle related 
exceptions
    
    * Remove useless Preconditions check
    
    * Remove useless Preconditions check
    
    * Add InvalidBindingTablesException to handle related exceptions
    
    * fix unit test
    
    * optimize class name
    
    * replace exception class
---
 .../user-manual/error-code/sql-error-code.cn.md    |  4 ++-
 .../user-manual/error-code/sql-error-code.en.md    |  2 ++
 .../data/NotImplementComparableValueException.java | 33 ++++++++++++++++++++++
 .../metadata/InvalidBindingTablesException.java    | 33 ++++++++++++++++++++++
 .../dql/groupby/GroupByMemoryMergedResult.java     |  5 ++--
 .../merge/dql/groupby/GroupByRowComparator.java    |  7 +++--
 .../dql/groupby/GroupByStreamMergedResult.java     | 13 +++++----
 .../sharding/merge/dql/orderby/OrderByValue.java   |  5 ++--
 ...ngGeneratedKeyInsertValueParameterRewriter.java |  5 ++--
 .../token/generator/impl/CursorTokenGenerator.java |  6 ++--
 .../impl/FetchDirectionTokenGenerator.java         |  2 --
 .../impl/InsertClauseShardingConditionEngine.java  |  5 ++--
 .../engine/condition/generator/ConditionValue.java |  7 +++--
 .../shardingsphere/sharding/rule/ShardingRule.java | 14 +++++----
 .../sharding/rule/ShardingRuleTest.java            | 11 ++++----
 .../checker/ShardingTableRuleStatementChecker.java |  9 +++---
 16 files changed, 119 insertions(+), 42 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 f5d78c7e83e..c228a61083e 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
@@ -143,7 +143,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 
 ### 数据分片
 
-| SQL State | Vendor Code | 错误信息                                               
                                                                       |
+| SQL State | Vendor Code | 错误信息                                               
                                                                          |
 | --------- 
|-------------|------------------------------------------------------------------------------------------------------------------------------|
 | 44000     | 20000       | Can not find table rule with logic tables \`%s\`.  
                                                                          |
 | 44000     | 20001       | Can not get uniformed table structure for logic 
table \`%s\`, it has different meta data of actual tables are as follows: %s |
@@ -157,10 +157,12 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | 42S01     | 20009       | View name has to bind to %s tables.                
                                                                          |
 | 44000     | 20010       | \`%s\` algorithm does not exist in database 
\`%s\`.                                                                         
 |
 | 44000     | 20011       | \`%s\` configuration does not exist in database 
\`%s\`.                                                                      |
+| 44000     | 20012       | Invalid binding table configuration in 
ShardingRuleConfiguration.                                                      
      |
 | 44000     | 20020       | Sharding value can't be null in insert statement.  
                                                                          |
 | HY004     | 20021       | Found different types for sharding value \`%s\`.   
                                                                          |
 | HY004     | 20022       | Invalid %s, datetime pattern should be \`%s\`, 
value is \`%s\`.                                                              |
 | 44000     | 20023       | Sharding value %s subtract stop offset %d can not 
be less than start offset %d.                                              |
+| 44000     | 20024       | %s value must implements Comparable.               
                                                                          |
 | 0A000     | 20040       | Can not support operation \`%s\` with sharding 
table \`%s\`.                                                                 |
 | 44000     | 20041       | Can not update sharding value for table \`%s\`.    
                                                                          |
 | 0A000     | 20042       | The CREATE VIEW statement contains unsupported 
query statement.                                                              |
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 0f6c7f01b2f..97c871ce650 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
@@ -157,10 +157,12 @@ SQL error codes provide by standard `SQL State`, `Vendor 
Code` and `Reason`, whi
 | 42S01     | 20009       | View name has to bind to %s tables.                
                                                                          |
 | 44000     | 20010       | \`%s\` algorithm does not exist in database 
\`%s\`.                                                                         
 |
 | 44000     | 20011       | \`%s\` configuration does not exist in database 
\`%s\`.                                                                      |
+| 44000     | 20012       | Invalid binding table configuration in 
ShardingRuleConfiguration.                                                      
      |
 | 44000     | 20020       | Sharding value can't be null in insert statement.  
                                                                          |
 | HY004     | 20021       | Found different types for sharding value \`%s\`.   
                                                                          |
 | HY004     | 20022       | Invalid %s, datetime pattern should be \`%s\`, 
value is \`%s\`.                                                              |
 | 44000     | 20023       | Sharding value %s subtract stop offset %d can not 
be less than start offset %d.                                              |
+| 44000     | 20024       | %s value must implements Comparable.               
                                                                          |
 | 0A000     | 20040       | Can not support operation \`%s\` with sharding 
table \`%s\`.                                                                 |
 | 44000     | 20041       | Can not update sharding value for table \`%s\`.    
                                                                          |
 | 0A000     | 20042       | The CREATE VIEW statement contains unsupported 
query statement.                                                              |
diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/data/NotImplementComparableValueException.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/data/NotImplementComparableValueException.java
new file mode 100644
index 00000000000..3f66d815915
--- /dev/null
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/data/NotImplementComparableValueException.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.data;
+
+import 
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
+import org.apache.shardingsphere.sharding.exception.ShardingSQLException;
+
+/**
+ * Not implement comparable value exception.
+ */
+public final class NotImplementComparableValueException extends 
ShardingSQLException {
+    
+    private static final long serialVersionUID = 1442602803378775261L;
+    
+    public NotImplementComparableValueException(final String segmentType) {
+        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 24, "%s value must 
implements Comparable.", segmentType);
+    }
+}
diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/InvalidBindingTablesException.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/InvalidBindingTablesException.java
new file mode 100644
index 00000000000..685ca795f1e
--- /dev/null
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/InvalidBindingTablesException.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.metadata;
+
+import 
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
+import org.apache.shardingsphere.sharding.exception.ShardingSQLException;
+
+/**
+ * Invalid binding tables exception.
+ */
+public final class InvalidBindingTablesException extends ShardingSQLException {
+    
+    private static final long serialVersionUID = 6913516240331555395L;
+    
+    public InvalidBindingTablesException() {
+        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 12, "Invalid binding table 
configuration in ShardingRuleConfiguration.");
+    }
+}
diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResult.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResult.java
index 852f73a0a3a..c2a3c8b9996 100644
--- 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResult.java
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResult.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.sharding.merge.dql.groupby;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.Maps;
 import 
org.apache.shardingsphere.infra.binder.segment.select.projection.Projection;
 import 
org.apache.shardingsphere.infra.binder.segment.select.projection.impl.AggregationDistinctProjection;
@@ -30,6 +29,8 @@ import 
org.apache.shardingsphere.infra.merge.result.impl.memory.MemoryQueryResul
 import 
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereColumn;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable;
+import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import 
org.apache.shardingsphere.sharding.exception.data.NotImplementComparableValueException;
 import 
org.apache.shardingsphere.sharding.merge.dql.groupby.aggregation.AggregationUnit;
 import 
org.apache.shardingsphere.sharding.merge.dql.groupby.aggregation.AggregationUnitFactory;
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
@@ -105,7 +106,7 @@ public final class GroupByMemoryMergedResult extends 
MemoryMergedResult<Sharding
     
     private Comparable<?> getAggregationValue(final QueryResult queryResult, 
final AggregationProjection aggregationProjection) throws SQLException {
         Object result = queryResult.getValue(aggregationProjection.getIndex(), 
Object.class);
-        Preconditions.checkState(null == result || result instanceof 
Comparable, "Aggregation value must implements Comparable");
+        ShardingSpherePreconditions.checkState(null == result || result 
instanceof Comparable, () -> new 
NotImplementComparableValueException("Aggregation"));
         return (Comparable<?>) result;
     }
     
diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByRowComparator.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByRowComparator.java
index 72e559db44c..89acaec7e18 100644
--- 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByRowComparator.java
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByRowComparator.java
@@ -17,11 +17,12 @@
 
 package org.apache.shardingsphere.sharding.merge.dql.groupby;
 
-import com.google.common.base.Preconditions;
 import lombok.RequiredArgsConstructor;
 import 
org.apache.shardingsphere.infra.binder.segment.select.orderby.OrderByItem;
 import 
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
 import 
org.apache.shardingsphere.infra.merge.result.impl.memory.MemoryQueryResultRow;
+import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import 
org.apache.shardingsphere.sharding.exception.data.NotImplementComparableValueException;
 import org.apache.shardingsphere.sharding.merge.dql.orderby.CompareUtil;
 
 import java.util.Collection;
@@ -50,9 +51,9 @@ public final class GroupByRowComparator implements 
Comparator<MemoryQueryResultR
     private int compare(final MemoryQueryResultRow o1, final 
MemoryQueryResultRow o2, final Collection<OrderByItem> orderByItems) {
         for (OrderByItem each : orderByItems) {
             Object orderValue1 = o1.getCell(each.getIndex());
-            Preconditions.checkState(null == orderValue1 || orderValue1 
instanceof Comparable, "Order by value must implements Comparable");
+            ShardingSpherePreconditions.checkState(null == orderValue1 || 
orderValue1 instanceof Comparable, () -> new 
NotImplementComparableValueException("Order by"));
             Object orderValue2 = o2.getCell(each.getIndex());
-            Preconditions.checkState(null == orderValue2 || orderValue2 
instanceof Comparable, "Order by value must implements Comparable");
+            ShardingSpherePreconditions.checkState(null == orderValue2 || 
orderValue2 instanceof Comparable, () -> new 
NotImplementComparableValueException("Order by"));
             int result = CompareUtil.compareTo((Comparable) orderValue1, 
(Comparable) orderValue2, each.getSegment().getOrderDirection(),
                     
each.getSegment().getNullsOrderType(selectStatementContext.getDatabaseType().getType()),
 valueCaseSensitive.get(each.getIndex()));
             if (0 != result) {
diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResult.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResult.java
index 1342fe3ae33..416e8967707 100644
--- 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResult.java
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResult.java
@@ -17,16 +17,17 @@
 
 package org.apache.shardingsphere.sharding.merge.dql.groupby;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.Maps;
-import 
org.apache.shardingsphere.sharding.merge.dql.groupby.aggregation.AggregationUnit;
-import 
org.apache.shardingsphere.sharding.merge.dql.groupby.aggregation.AggregationUnitFactory;
-import 
org.apache.shardingsphere.sharding.merge.dql.orderby.OrderByStreamMergedResult;
-import 
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
 import 
org.apache.shardingsphere.infra.binder.segment.select.projection.impl.AggregationDistinctProjection;
 import 
org.apache.shardingsphere.infra.binder.segment.select.projection.impl.AggregationProjection;
 import 
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
+import 
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
+import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import 
org.apache.shardingsphere.sharding.exception.data.NotImplementComparableValueException;
+import 
org.apache.shardingsphere.sharding.merge.dql.groupby.aggregation.AggregationUnit;
+import 
org.apache.shardingsphere.sharding.merge.dql.groupby.aggregation.AggregationUnitFactory;
+import 
org.apache.shardingsphere.sharding.merge.dql.orderby.OrderByStreamMergedResult;
 
 import java.sql.SQLException;
 import java.util.ArrayList;
@@ -114,7 +115,7 @@ public final class GroupByStreamMergedResult extends 
OrderByStreamMergedResult {
     
     private Comparable<?> getAggregationValue(final AggregationProjection 
aggregationProjection) throws SQLException {
         Object result = 
getCurrentQueryResult().getValue(aggregationProjection.getIndex(), 
Object.class);
-        Preconditions.checkState(null == result || result instanceof 
Comparable, "Aggregation value must implements Comparable");
+        ShardingSpherePreconditions.checkState(null == result || result 
instanceof Comparable, () -> new 
NotImplementComparableValueException("Aggregation"));
         return (Comparable<?>) result;
     }
     
diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValue.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValue.java
index 4a5448034d1..837c81f46e4 100644
--- 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValue.java
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValue.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.sharding.merge.dql.orderby;
 
-import com.google.common.base.Preconditions;
 import lombok.Getter;
 import 
org.apache.shardingsphere.infra.binder.segment.select.orderby.OrderByItem;
 import 
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
@@ -25,6 +24,8 @@ import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryRe
 import 
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereColumn;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable;
+import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import 
org.apache.shardingsphere.sharding.exception.data.NotImplementComparableValueException;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.ColumnOrderByItemSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.IndexOrderByItemSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.OrderByItemSegment;
@@ -109,7 +110,7 @@ public final class OrderByValue implements 
Comparable<OrderByValue> {
         List<Comparable<?>> result = new ArrayList<>(orderByItems.size());
         for (OrderByItem each : orderByItems) {
             Object value = queryResult.getValue(each.getIndex(), Object.class);
-            Preconditions.checkState(null == value || value instanceof 
Comparable, "Order by value must implements Comparable");
+            ShardingSpherePreconditions.checkState(null == value || value 
instanceof Comparable, () -> new NotImplementComparableValueException("Order 
by"));
             result.add((Comparable<?>) value);
         }
         return result;
diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/parameter/impl/ShardingGeneratedKeyInsertValueParameterRewriter.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/parameter/impl/ShardingGeneratedKeyInsertValueParameterRewriter.java
index 880d2d982a1..08120864a6f 100644
--- 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/parameter/impl/ShardingGeneratedKeyInsertValueParameterRewriter.java
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/parameter/impl/ShardingGeneratedKeyInsertValueParameterRewriter.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.sharding.rewrite.parameter.impl;
 
-import com.google.common.base.Preconditions;
 import lombok.Setter;
 import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
 import 
org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
@@ -46,7 +45,9 @@ public final class 
ShardingGeneratedKeyInsertValueParameterRewriter implements P
     
     @Override
     public void rewrite(final ParameterBuilder paramBuilder, final 
InsertStatementContext insertStatementContext, final List<Object> params) {
-        
Preconditions.checkState(insertStatementContext.getGeneratedKeyContext().isPresent());
+        if (!insertStatementContext.getGeneratedKeyContext().isPresent()) {
+            return;
+        }
         ((GroupedParameterBuilder) 
paramBuilder).setDerivedColumnName(insertStatementContext.getGeneratedKeyContext().get().getColumnName());
         Iterator<Comparable<?>> generatedValues = 
insertStatementContext.getGeneratedKeyContext().get().getGeneratedValues().iterator();
         int count = 0;
diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/CursorTokenGenerator.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/CursorTokenGenerator.java
index d45ed027edd..f1805d60d12 100644
--- 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/CursorTokenGenerator.java
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/CursorTokenGenerator.java
@@ -17,12 +17,12 @@
 
 package org.apache.shardingsphere.sharding.rewrite.token.generator.impl;
 
-import com.google.common.base.Preconditions;
 import lombok.Setter;
 import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
 import org.apache.shardingsphere.infra.binder.type.CursorAvailable;
 import 
org.apache.shardingsphere.infra.rewrite.sql.token.generator.OptionalSQLTokenGenerator;
 import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
+import 
org.apache.shardingsphere.sharding.exception.connection.CursorNameNotFoundException;
 import org.apache.shardingsphere.sharding.rewrite.token.pojo.CursorToken;
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
 import org.apache.shardingsphere.sharding.rule.aware.ShardingRuleAware;
@@ -43,9 +43,7 @@ public final class CursorTokenGenerator implements 
OptionalSQLTokenGenerator<SQL
     
     @Override
     public SQLToken generateSQLToken(final SQLStatementContext<?> 
sqlStatementContext) {
-        Preconditions.checkArgument(sqlStatementContext instanceof 
CursorAvailable, "SQLStatementContext must implementation CursorAvailable 
interface.");
-        Preconditions.checkArgument(((CursorAvailable) 
sqlStatementContext).getCursorName().isPresent(), "Can not get cursor name from 
SQLStatementContext.");
-        CursorNameSegment cursorName = ((CursorAvailable) 
sqlStatementContext).getCursorName().get();
+        CursorNameSegment cursorName = ((CursorAvailable) 
sqlStatementContext).getCursorName().orElseThrow(CursorNameNotFoundException::new);
         return new CursorToken(cursorName.getStartIndex(), 
cursorName.getStopIndex(), cursorName.getIdentifier(), sqlStatementContext, 
shardingRule);
     }
 }
diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/FetchDirectionTokenGenerator.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/FetchDirectionTokenGenerator.java
index 82f52d3c15d..65e8d625b73 100644
--- 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/FetchDirectionTokenGenerator.java
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/FetchDirectionTokenGenerator.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.sharding.rewrite.token.generator.impl;
 
-import com.google.common.base.Preconditions;
 import lombok.Setter;
 import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
 import 
org.apache.shardingsphere.infra.binder.statement.ddl.FetchStatementContext;
@@ -46,7 +45,6 @@ public final class FetchDirectionTokenGenerator implements 
OptionalSQLTokenGener
     
     @Override
     public SQLToken generateSQLToken(final SQLStatementContext<?> 
sqlStatementContext) {
-        Preconditions.checkArgument(sqlStatementContext instanceof 
FetchStatementContext, "SQLStatementContext must be instance of 
FetchStatementContext.");
         FetchStatement fetchStatement = ((FetchStatementContext) 
sqlStatementContext).getSqlStatement();
         CursorNameSegment cursorName = fetchStatement.getCursorName();
         int startIndex = 
fetchStatement.getDirection().map(DirectionSegment::getStartIndex).orElseGet("FETCH"::length);
diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/InsertClauseShardingConditionEngine.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/InsertClauseShardingConditionEngine.java
index d0be26c0485..787536cec11 100644
--- 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/InsertClauseShardingConditionEngine.java
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/InsertClauseShardingConditionEngine.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.sharding.route.engine.condition.engine.impl;
 
-import com.google.common.base.Preconditions;
 import lombok.RequiredArgsConstructor;
 import 
org.apache.shardingsphere.dialect.exception.data.InsertColumnsAndValuesMismatchedException;
 import 
org.apache.shardingsphere.infra.binder.segment.insert.keygen.GeneratedKeyContext;
@@ -26,7 +25,9 @@ import 
org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementConte
 import 
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
 import org.apache.shardingsphere.infra.datetime.DatetimeService;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
 import 
org.apache.shardingsphere.infra.util.spi.type.required.RequiredSPIRegistry;
+import 
org.apache.shardingsphere.sharding.exception.data.NotImplementComparableValueException;
 import 
org.apache.shardingsphere.sharding.exception.data.NullShardingValueException;
 import 
org.apache.shardingsphere.sharding.route.engine.condition.ExpressionConditionUtils;
 import 
org.apache.shardingsphere.sharding.route.engine.condition.ShardingCondition;
@@ -141,7 +142,7 @@ public final class InsertClauseShardingConditionEngine {
         Object result = expressionSegment instanceof 
ParameterMarkerExpressionSegment
                 ? params.get(((ParameterMarkerExpressionSegment) 
expressionSegment).getParameterMarkerIndex())
                 : ((LiteralExpressionSegment) expressionSegment).getLiterals();
-        Preconditions.checkArgument(result instanceof Comparable, "Sharding 
value must implements Comparable");
+        ShardingSpherePreconditions.checkState(result instanceof Comparable, 
() -> new NotImplementComparableValueException("Sharding"));
         return (Comparable) result;
     }
     
diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/ConditionValue.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/ConditionValue.java
index bd7f97e4823..fa078d1a236 100644
--- 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/ConditionValue.java
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/ConditionValue.java
@@ -17,7 +17,8 @@
 
 package org.apache.shardingsphere.sharding.route.engine.condition.generator;
 
-import com.google.common.base.Preconditions;
+import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import 
org.apache.shardingsphere.sharding.exception.data.NotImplementComparableValueException;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.LiteralExpressionSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.ParameterMarkerExpressionSegment;
@@ -53,7 +54,7 @@ public final class ConditionValue {
         int parameterMarkerIndex = expressionSegment.getParameterMarkerIndex();
         if (parameterMarkerIndex < params.size()) {
             Object result = params.get(parameterMarkerIndex);
-            Preconditions.checkArgument(result instanceof Comparable, 
"Sharding value must implements Comparable.");
+            ShardingSpherePreconditions.checkState(result instanceof 
Comparable, () -> new NotImplementComparableValueException("Sharding"));
             return (Comparable<?>) result;
         }
         return null;
@@ -61,7 +62,7 @@ public final class ConditionValue {
     
     private Comparable<?> getValue(final LiteralExpressionSegment 
expressionSegment) {
         Object result = expressionSegment.getLiterals();
-        Preconditions.checkArgument(result instanceof Comparable, "Sharding 
value must implements Comparable.");
+        ShardingSpherePreconditions.checkState(result instanceof Comparable, 
() -> new NotImplementComparableValueException("Sharding"));
         return (Comparable<?>) result;
     }
     
diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
index 63474f1220f..83f88678b07 100644
--- 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.sharding.rule;
 
-import com.google.common.base.Preconditions;
 import com.google.common.base.Splitter;
 import com.google.common.base.Strings;
 import lombok.Getter;
@@ -49,6 +48,8 @@ import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingS
 import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.api.sharding.ShardingAutoTableAlgorithm;
 import 
org.apache.shardingsphere.sharding.exception.algorithm.keygen.GenerateKeyStrategyNotFoundException;
+import 
org.apache.shardingsphere.sharding.exception.algorithm.sharding.ShardingAlgorithmClassImplementationException;
+import 
org.apache.shardingsphere.sharding.exception.metadata.InvalidBindingTablesException;
 import 
org.apache.shardingsphere.sharding.exception.metadata.ShardingRuleNotFoundException;
 import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
 import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
@@ -132,9 +133,9 @@ public final class ShardingRule implements DatabaseRule, 
DataNodeContainedRule,
                 : 
keyGenerators.get(ruleConfig.getDefaultKeyGenerateStrategy().getKeyGeneratorName());
         defaultShardingColumn = ruleConfig.getDefaultShardingColumn();
         shardingTableDataNodes = createShardingTableDataNodes(tableRules);
-        
Preconditions.checkArgument(isValidBindingTableConfiguration(tableRules, new 
BindingTableCheckedConfiguration(this.dataSourceNames, shardingAlgorithms, 
ruleConfig.getBindingTableGroups(),
-                broadcastTables, defaultDatabaseShardingStrategyConfig, 
defaultTableShardingStrategyConfig, defaultShardingColumn)),
-                "Invalid binding table configuration in 
ShardingRuleConfiguration.");
+        
ShardingSpherePreconditions.checkState(isValidBindingTableConfiguration(tableRules,
 new BindingTableCheckedConfiguration(this.dataSourceNames, shardingAlgorithms,
+                ruleConfig.getBindingTableGroups(), broadcastTables, 
defaultDatabaseShardingStrategyConfig, defaultTableShardingStrategyConfig, 
defaultShardingColumn)),
+                InvalidBindingTablesException::new);
         keyGenerators.values().stream().filter(each -> each instanceof 
InstanceContextAware).forEach(each -> ((InstanceContextAware) 
each).setInstanceContext(instanceContext));
         if (defaultKeyGenerateAlgorithm instanceof InstanceContextAware) {
             ((InstanceContextAware) 
defaultKeyGenerateAlgorithm).setInstanceContext(instanceContext);
@@ -185,8 +186,9 @@ public final class ShardingRule implements DatabaseRule, 
DataNodeContainedRule,
     }
     
     private TableRule createAutoTableRule(final 
KeyGenerateStrategyConfiguration defaultKeyGenerateStrategyConfig, final 
ShardingAutoTableRuleConfiguration autoTableRuleConfig) {
-        ShardingAlgorithm shardingAlgorithm = null == 
autoTableRuleConfig.getShardingStrategy() ? null : 
shardingAlgorithms.get(autoTableRuleConfig.getShardingStrategy().getShardingAlgorithmName());
-        Preconditions.checkState(shardingAlgorithm instanceof 
ShardingAutoTableAlgorithm, "Sharding auto table rule configuration must match 
sharding auto table algorithm.");
+        ShardingAlgorithm shardingAlgorithm = 
shardingAlgorithms.get(autoTableRuleConfig.getShardingStrategy().getShardingAlgorithmName());
+        ShardingSpherePreconditions.checkState(shardingAlgorithm instanceof 
ShardingAutoTableAlgorithm,
+                () -> new 
ShardingAlgorithmClassImplementationException(autoTableRuleConfig.getShardingStrategy().getShardingAlgorithmName(),
 ShardingAutoTableAlgorithm.class));
         return new TableRule(autoTableRuleConfig, dataSourceNames, 
(ShardingAutoTableAlgorithm) shardingAlgorithm, 
getDefaultGenerateKeyColumn(defaultKeyGenerateStrategyConfig));
     }
     
diff --git 
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
index 468d76c3bb0..963847042b5 100644
--- 
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
+++ 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
@@ -43,6 +43,7 @@ import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.NoneShard
 import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.exception.algorithm.keygen.GenerateKeyStrategyNotFoundException;
+import 
org.apache.shardingsphere.sharding.exception.metadata.InvalidBindingTablesException;
 import 
org.apache.shardingsphere.sharding.exception.metadata.ShardingRuleNotFoundException;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
@@ -301,7 +302,7 @@ public final class ShardingRuleTest {
         createMaximumShardingRule().generateKey("table_0");
     }
     
-    @Test(expected = IllegalArgumentException.class)
+    @Test(expected = InvalidBindingTablesException.class)
     public void assertCreateInconsistentActualDataSourceNamesFailure() {
         ShardingRuleConfiguration shardingRuleConfig = new 
ShardingRuleConfiguration();
         ShardingTableRuleConfiguration shardingTableRuleConfig = 
createTableRuleConfiguration("LOGIC_TABLE", "ds_${0..2}.table_${0..2}");
@@ -313,7 +314,7 @@ public final class ShardingRuleTest {
         new ShardingRule(shardingRuleConfig, createDataSourceNames(), 
mock(InstanceContext.class));
     }
     
-    @Test(expected = IllegalArgumentException.class)
+    @Test(expected = InvalidBindingTablesException.class)
     public void assertCreateInconsistentActualTableNamesFailure() {
         ShardingRuleConfiguration shardingRuleConfig = new 
ShardingRuleConfiguration();
         ShardingTableRuleConfiguration shardingTableRuleConfig = 
createTableRuleConfiguration("LOGIC_TABLE", "ds_${0..1}.table_${0..3}");
@@ -325,7 +326,7 @@ public final class ShardingRuleTest {
         new ShardingRule(shardingRuleConfig, createDataSourceNames(), 
mock(InstanceContext.class));
     }
     
-    @Test(expected = IllegalArgumentException.class)
+    @Test(expected = InvalidBindingTablesException.class)
     public void 
assertCreateInconsistentAlgorithmExpressionOnDatabaseShardingStrategyFailure() {
         ShardingRuleConfiguration shardingRuleConfig = new 
ShardingRuleConfiguration();
         ShardingTableRuleConfiguration shardingTableRuleConfig = 
createTableRuleConfiguration("LOGIC_TABLE", "ds_${0..1}.table_${0..2}");
@@ -340,7 +341,7 @@ public final class ShardingRuleTest {
         new ShardingRule(shardingRuleConfig, createDataSourceNames(), 
mock(InstanceContext.class));
     }
     
-    @Test(expected = IllegalArgumentException.class)
+    @Test(expected = InvalidBindingTablesException.class)
     public void 
assertCreateInconsistentAlgorithmExpressionOnTableShardingStrategyFailure() {
         ShardingRuleConfiguration shardingRuleConfig = new 
ShardingRuleConfiguration();
         ShardingTableRuleConfiguration shardingTableRuleConfig = 
createTableRuleConfiguration("LOGIC_TABLE", "ds_${0..1}.table_${0..2}");
@@ -357,7 +358,7 @@ public final class ShardingRuleTest {
         new ShardingRule(shardingRuleConfig, createDataSourceNames(), 
mock(InstanceContext.class));
     }
     
-    @Test(expected = IllegalArgumentException.class)
+    @Test(expected = InvalidBindingTablesException.class)
     public void 
assertCreateInconsistentAlgorithmExpressionWithDefaultAndSpecifiedTableShardingStrategyFailure()
 {
         ShardingRuleConfiguration shardingRuleConfig = new 
ShardingRuleConfiguration();
         ShardingTableRuleConfiguration shardingTableRuleConfig = 
createTableRuleConfiguration("LOGIC_TABLE", "ds_${0..1}.table_${0..2}");
diff --git 
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java
 
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java
index 3e3c2c6c00e..785ab08d73b 100644
--- 
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java
+++ 
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java
@@ -17,14 +17,13 @@
 
 package org.apache.shardingsphere.sharding.distsql.handler.checker;
 
-import com.google.common.base.Preconditions;
 import com.google.common.base.Splitter;
 import 
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
 import 
org.apache.shardingsphere.distsql.handler.exception.algorithm.MissingRequiredAlgorithmException;
-import 
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
 import 
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
 import 
org.apache.shardingsphere.distsql.handler.exception.rule.InvalidRuleConfigurationException;
 import 
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
+import 
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
 import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
 import 
org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
@@ -52,6 +51,7 @@ import 
org.apache.shardingsphere.sharding.distsql.parser.segment.strategy.Shardi
 import 
org.apache.shardingsphere.sharding.distsql.parser.segment.table.AbstractTableRuleSegment;
 import 
org.apache.shardingsphere.sharding.distsql.parser.segment.table.AutoTableRuleSegment;
 import 
org.apache.shardingsphere.sharding.distsql.parser.segment.table.TableRuleSegment;
+import 
org.apache.shardingsphere.sharding.exception.algorithm.sharding.ShardingAlgorithmClassImplementationException;
 import 
org.apache.shardingsphere.sharding.exception.metadata.ShardingRuleNotFoundException;
 import 
org.apache.shardingsphere.sharding.rule.BindingTableCheckedConfiguration;
 import org.apache.shardingsphere.sharding.rule.TableRule;
@@ -484,8 +484,9 @@ public final class ShardingTableRuleStatementChecker {
     
     private static TableRule createAutoTableRule(final 
KeyGenerateStrategyConfiguration defaultKeyGenerateStrategyConfig, final 
ShardingAutoTableRuleConfiguration autoTableRuleConfig,
                                                  final Map<String, 
ShardingAlgorithm> shardingAlgorithms, final Collection<String> 
dataSourceNames) {
-        ShardingAlgorithm shardingAlgorithm = null == 
autoTableRuleConfig.getShardingStrategy() ? null : 
shardingAlgorithms.get(autoTableRuleConfig.getShardingStrategy().getShardingAlgorithmName());
-        Preconditions.checkState(shardingAlgorithm instanceof 
ShardingAutoTableAlgorithm, "Sharding auto table rule configuration must match 
sharding auto table algorithm.");
+        ShardingAlgorithm shardingAlgorithm = 
shardingAlgorithms.get(autoTableRuleConfig.getShardingStrategy().getShardingAlgorithmName());
+        ShardingSpherePreconditions.checkState(shardingAlgorithm instanceof 
ShardingAutoTableAlgorithm,
+                () -> new 
ShardingAlgorithmClassImplementationException(autoTableRuleConfig.getShardingStrategy().getShardingAlgorithmName(),
 ShardingAutoTableAlgorithm.class));
         return new TableRule(autoTableRuleConfig, dataSourceNames, 
(ShardingAutoTableAlgorithm) shardingAlgorithm, 
getDefaultGenerateKeyColumn(defaultKeyGenerateStrategyConfig));
     }
     


Reply via email to