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 2cc77b4b156 ConditionValueInOperatorGenerator not excluding the case 
of not in. (#32076) (#32078)
2cc77b4b156 is described below

commit 2cc77b4b1563ec9fd9df5d024df81d979f81bef7
Author: YaoFly <[email protected]>
AuthorDate: Tue Jul 16 10:36:03 2024 +0800

    ConditionValueInOperatorGenerator not excluding the case of not in. 
(#32076) (#32078)
    
    * ConditionValueInOperatorGenerator not excluding the case of not in. 
(#32076)
    
    * Add 'not in' test case for ConditionValueInOperatorGenerator (#32076)
---
 .../generator/impl/ConditionValueInOperatorGenerator.java      |  3 +++
 .../generator/impl/ConditionValueInOperatorGeneratorTest.java  | 10 ++++++++++
 2 files changed, 13 insertions(+)

diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueInOperatorGenerator.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueInOperatorGenerator.java
index 87b9013e7d6..6b3cb7751ef 100644
--- 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueInOperatorGenerator.java
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueInOperatorGenerator.java
@@ -41,6 +41,9 @@ public final class ConditionValueInOperatorGenerator 
implements ConditionValueGe
     @Override
     public Optional<ShardingConditionValue> generate(final InExpression 
predicate, final Column column, final List<Object> params, final 
TimestampServiceRule timestampServiceRule) {
         List<Comparable<?>> shardingConditionValues = new LinkedList<>();
+        if (predicate.isNot()) {
+            return Optional.empty();
+        }
         Collection<ExpressionSegment> expressionSegments = 
predicate.getExpressionList();
         List<Integer> parameterMarkerIndexes = new 
ArrayList<>(expressionSegments.size());
         for (ExpressionSegment each : expressionSegments) {
diff --git 
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueInOperatorGeneratorTest.java
 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueInOperatorGeneratorTest.java
index feb664c517c..52b8323aa06 100644
--- 
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueInOperatorGeneratorTest.java
+++ 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueInOperatorGeneratorTest.java
@@ -117,4 +117,14 @@ class ConditionValueInOperatorGeneratorTest {
         Optional<ShardingConditionValue> actual = 
generator.generate(predicate, column, new LinkedList<>(), timestampServiceRule);
         assertFalse(actual.isPresent());
     }
+    
+    @Test
+    void assertNotInExpression() {
+        ColumnSegment left = new ColumnSegment(0, 0, new 
IdentifierValue("id"));
+        ListExpression right = new ListExpression(0, 0);
+        right.getItems().add(new ParameterMarkerExpressionSegment(0, 0, 0));
+        InExpression inExpression = new InExpression(0, 0, left, right, true);
+        Optional<ShardingConditionValue> shardingConditionValue = 
generator.generate(inExpression, column, Collections.singletonList(1), 
timestampServiceRule);
+        assertFalse(shardingConditionValue.isPresent());
+    }
 }

Reply via email to