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

zhaojinchao 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 eb6c161acc9 Add InExpression for extractParameterMarkerExpressions in 
ExpressionExtractUtils (#25139)
eb6c161acc9 is described below

commit eb6c161acc910980908da2f385abdaf53abc5b24
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Wed Apr 12 16:05:04 2023 +0800

    Add InExpression for extractParameterMarkerExpressions in 
ExpressionExtractUtils (#25139)
---
 .../sql/parser/sql/common/util/ExpressionExtractUtils.java   |  4 ++++
 .../parser/sql/common/util/ExpressionExtractUtilsTest.java   | 12 ++++++++++++
 2 files changed, 16 insertions(+)

diff --git 
a/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/ExpressionExtractUtils.java
 
b/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/ExpressionExtractUtils.java
index 517d7e57590..1b0bb4fd696 100644
--- 
a/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/ExpressionExtractUtils.java
+++ 
b/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/ExpressionExtractUtils.java
@@ -23,6 +23,7 @@ import 
org.apache.shardingsphere.sql.parser.sql.common.enums.LogicalOperator;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.FunctionSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.InExpression;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.TypeCastExpression;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.ParameterMarkerExpressionSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.AndPredicate;
@@ -115,6 +116,9 @@ public final class ExpressionExtractUtils {
             if (each instanceof TypeCastExpression) {
                 extractParameterMarkerExpressions(result, 
Collections.singletonList(((TypeCastExpression) each).getExpression()));
             }
+            if (each instanceof InExpression) {
+                extractParameterMarkerExpressions(result, ((InExpression) 
each).getExpressionList());
+            }
         }
     }
 }
diff --git 
a/sql-parser/statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/ExpressionExtractUtilsTest.java
 
b/sql-parser/statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/ExpressionExtractUtilsTest.java
index 1009419bcef..d89cca0e5be 100644
--- 
a/sql-parser/statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/ExpressionExtractUtilsTest.java
+++ 
b/sql-parser/statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/ExpressionExtractUtilsTest.java
@@ -22,6 +22,8 @@ import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.Column
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.FunctionSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.InExpression;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ListExpression;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.TypeCastExpression;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.complex.CommonExpressionSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.LiteralExpressionSegment;
@@ -129,4 +131,14 @@ class ExpressionExtractUtilsTest {
         assertThat(actual.size(), is(1));
         assertThat(actual.get(0), is(expected));
     }
+    
+    @Test
+    void assertGetParameterMarkerExpressionsFromInExpression() {
+        ListExpression listExpression = new ListExpression(0, 0);
+        listExpression.getItems().add(new ParameterMarkerExpressionSegment(0, 
0, 1, ParameterMarkerType.QUESTION));
+        listExpression.getItems().add(new ParameterMarkerExpressionSegment(0, 
0, 2, ParameterMarkerType.QUESTION));
+        List<ExpressionSegment> inExpressions = Collections.singletonList(new 
InExpression(0, 0, new ColumnSegment(0, 0, new IdentifierValue("order_id")), 
listExpression, false));
+        List<ParameterMarkerExpressionSegment> actual = 
ExpressionExtractUtils.getParameterMarkerExpressions(inExpressions);
+        assertThat(actual.size(), is(2));
+    }
 }

Reply via email to