This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 7e32b4ee62b Fix parsing not like operator missing whitespace. (#22202)
7e32b4ee62b is described below
commit 7e32b4ee62bec6e3adc9518cf6977dabab9068ad
Author: Chuxin Chen <[email protected]>
AuthorDate: Wed Nov 16 15:49:04 2022 +0800
Fix parsing not like operator missing whitespace. (#22202)
---
.../impl/OpenGaussStatementSQLVisitor.java | 2 +-
.../impl/PostgreSQLStatementSQLVisitor.java | 2 +-
.../main/resources/case/dml/select-expression.xml | 28 ++++++++++++++++++++++
.../sql/supported/dml/select-expression.xml | 1 +
4 files changed, 31 insertions(+), 2 deletions(-)
diff --git
a/sql-parser/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussStatementSQLVisitor.java
b/sql-parser/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussStatementSQLVisitor.java
index d11bc2fe488..ef50c68c2ca 100644
---
a/sql-parser/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussStatementSQLVisitor.java
+++
b/sql-parser/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussStatementSQLVisitor.java
@@ -336,7 +336,7 @@ public abstract class OpenGaussStatementSQLVisitor extends
OpenGaussStatementBas
}
private BinaryOperationExpression
createPatternMatchingOperationSegment(final AExprContext ctx) {
- String operator = ctx.patternMatchingOperator().getText();
+ String operator = getOriginalText(ctx.patternMatchingOperator());
ExpressionSegment left = (ExpressionSegment) visit(ctx.aExpr(0));
ListExpression right = new
ListExpression(ctx.aExpr(1).start.getStartIndex(),
ctx.aExpr().get(ctx.aExpr().size() - 1).stop.getStopIndex());
for (int i = 1; i < ctx.aExpr().size(); i++) {
diff --git
a/sql-parser/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
b/sql-parser/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
index 71b89a98039..03cdfaab3fb 100644
---
a/sql-parser/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
+++
b/sql-parser/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
@@ -336,7 +336,7 @@ public abstract class PostgreSQLStatementSQLVisitor extends
PostgreSQLStatementP
}
private BinaryOperationExpression
createPatternMatchingOperationSegment(final AExprContext ctx) {
- String operator = ctx.patternMatchingOperator().getText();
+ String operator = getOriginalText(ctx.patternMatchingOperator());
ExpressionSegment left = (ExpressionSegment) visit(ctx.aExpr(0));
ListExpression right = new
ListExpression(ctx.aExpr(1).start.getStartIndex(),
ctx.aExpr().get(ctx.aExpr().size() - 1).stop.getStopIndex());
for (int i = 1; i < ctx.aExpr().size(); i++) {
diff --git a/test/parser/src/main/resources/case/dml/select-expression.xml
b/test/parser/src/main/resources/case/dml/select-expression.xml
index fe1bb74733d..4b7300d2d11 100644
--- a/test/parser/src/main/resources/case/dml/select-expression.xml
+++ b/test/parser/src/main/resources/case/dml/select-expression.xml
@@ -906,6 +906,34 @@
</where>
</select>
+ <select sql-case-id="select_where_with_predicate_with_not_like">
+ <from start-index="14" stop-index="20">
+ <simple-table name="t_order" start-index="14" stop-index="20"/>
+ </from>
+ <projections distinct-row="false" start-index="7" stop-index="7">
+ <shorthand-projection start-index="7" stop-index="7"/>
+ </projections>
+ <where start-index="22" stop-index="55">
+ <expr>
+ <binary-operation-expression start-index="28" stop-index="55">
+ <left>
+ <column name="status" start-index="28" stop-index="41">
+ <owner name="t_order" start-index="28"
stop-index="34"/>
+ </column>
+ </left>
+ <operator>NOT LIKE</operator>
+ <right>
+ <list-expression start-index="52" stop-index="55">
+ <items>
+ <literal-expression value="1%"
start-index="52" stop-index="55"/>
+ </items>
+ </list-expression>
+ </right>
+ </binary-operation-expression>
+ </expr>
+ </where>
+ </select>
+
<select sql-case-id="select_where_with_predicate_with_regexp">
<from start-index="14" stop-index="20">
<simple-table name="t_order" start-index="14" stop-index="20"/>
diff --git
a/test/parser/src/main/resources/sql/supported/dml/select-expression.xml
b/test/parser/src/main/resources/sql/supported/dml/select-expression.xml
index 83b8486391f..5690e34774f 100644
--- a/test/parser/src/main/resources/sql/supported/dml/select-expression.xml
+++ b/test/parser/src/main/resources/sql/supported/dml/select-expression.xml
@@ -43,6 +43,7 @@
<sql-case id="select_where_with_predicate_with_between" value="SELECT *
FROM t_order WHERE t_order.order_id BETWEEN ? AND ?" db-types="MySQL" />
<sql-case id="select_where_with_predicate_with_sounds_like" value="SELECT
* FROM t_order WHERE t_order.order_id SOUNDS LIKE '1%'" db-types="MySQL" />
<sql-case id="select_where_with_predicate_with_like" value="SELECT * FROM
t_order WHERE t_order.order_id NOT LIKE '1%' ESCAPE '$'" db-types="MySQL" />
+ <sql-case id="select_where_with_predicate_with_not_like" value="SELECT *
FROM t_order WHERE t_order.status NOT LIKE '1%'"
db-types="MySQL,PostgreSQL,openGauss" />
<sql-case id="select_where_with_predicate_with_regexp" value="SELECT *
FROM t_order WHERE t_order.order_id NOT REGEXP '[123]'" db-types="MySQL" />
<sql-case id="select_where_with_bit_expr_with_vertical_bar" value="SELECT
* FROM t_order WHERE t_order.order_id | ?" db-types="MySQL" />
<sql-case id="select_where_with_bit_expr_with_ampersand" value="SELECT *
FROM t_order WHERE t_order.order_id & ?" db-types="MySQL" />