You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/04/04 09:41:53 UTC
[shardingsphere] branch master updated: fix issue#9899 (#9912)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 1d451bf fix issue#9899 (#9912)
1d451bf is described below
commit 1d451bfb96b4fe1de3cb403defe3b25e7da2b6b6
Author: JingShang Lu <lu...@apache.org>
AuthorDate: Sun Apr 4 17:41:22 2021 +0800
fix issue#9899 (#9912)
---
.../src/main/antlr4/imports/postgresql/BaseRule.g4 | 12 ++++++------
.../impl/PostgreSQLStatementSQLVisitor.java | 10 ++++++++++
.../src/main/resources/case/dml/select.xml | 22 ++++++++++++++++++++++
.../main/resources/sql/supported/dml/select.xml | 1 +
4 files changed, 39 insertions(+), 6 deletions(-)
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/BaseRule.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/BaseRule.g4
index 21e67fe..7d2477a 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/BaseRule.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/BaseRule.g4
@@ -530,10 +530,10 @@ aExpr
| aExpr LIKE aExpr ESCAPE aExpr
| aExpr NOT LIKE aExpr
| aExpr NOT LIKE aExpr ESCAPE aExpr
- | aExpr ILIKE aExpr
- | aExpr ILIKE aExpr ESCAPE aExpr
- | aExpr NOT ILIKE aExpr
- | aExpr NOT ILIKE aExpr ESCAPE aExpr
+ | aExpr TILDE_ aExpr
+ | aExpr TILDE_ aExpr ESCAPE aExpr
+ | aExpr NOT_ TILDE_ aExpr
+ | aExpr NOT_ TILDE_ aExpr ESCAPE aExpr
| aExpr SIMILAR TO aExpr
| aExpr SIMILAR TO aExpr ESCAPE aExpr
| aExpr NOT SIMILAR TO aExpr
@@ -667,8 +667,8 @@ subqueryOp
| OPERATOR LP_ anyOperator RP_
| LIKE
| NOT LIKE
- | ILIKE
- | NOT ILIKE
+ | TILDE_
+ | NOT_ TILDE_
;
allOp
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
index 1c39f87..701d4b8 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
@@ -188,6 +188,16 @@ public abstract class PostgreSQLStatementSQLVisitor extends PostgreSQLStatementB
if (null != ctx.IN()) {
return createInSegment(ctx);
}
+ if (null != ctx.TILDE_()) {
+ String operator = "~";
+ if (null != ctx.NOT_()) {
+ operator = "!~";
+ }
+ ExpressionSegment left = (ExpressionSegment) visit(ctx.aExpr(0));
+ ExpressionSegment right = (ExpressionSegment) visit(ctx.aExpr(1));
+ String text = ctx.start.getInputStream().getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
+ return new BinaryOperationExpression(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), left, right, operator, text);
+ }
if (null != ctx.comparisonOperator()) {
ExpressionSegment left = (ExpressionSegment) visit(ctx.aExpr(0));
ExpressionSegment right = (ExpressionSegment) visit(ctx.aExpr(1));
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/select.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/select.xml
index 7dd59f3..d426920 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/select.xml
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/select.xml
@@ -23,6 +23,28 @@
</projections>
</select>
+ <select sql-case-id="select_with_operator_ilike" >
+ <projections start-index="7" stop-index="8">
+ <column-projection name="id" start-index="7" stop-index="8"/>
+ </projections>
+ <from>
+ <simple-table name="t_order" start-index="15" stop-index="21" />
+ </from>
+ <where start-index="23" stop-index="47">
+ <expr>
+ <binary-operation-expression start-index="29" stop-index="47">
+ <left>
+ <column name="name" start-index="29" stop-index="32"/>
+ </left>
+ <right>
+ <literal-expression value="^pg_toast" start-index="37" stop-index="47"/>
+ </right>
+ <operator>!~</operator>
+ </binary-operation-expression>
+ </expr>
+ </where>
+ </select>
+
<select sql-case-id="select_with_binary_operation_of_aggregation_expr" >
<projections start-index="7" stop-index="23">
<expression-projection text="count(*)+1" alias="a" start-index="8" stop-index="23" />
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/select.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/select.xml
index 98e184a..e437bf7 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/select.xml
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/select.xml
@@ -18,6 +18,7 @@
<sql-cases>
<sql-case id="select_constant_without_table" value="SELECT 1 as a" />
+ <sql-case id="select_with_operator_ilike" value="SELECT id from t_order where name !~ '^pg_toast'" db-types="PostgreSQL"/>
<sql-case id="select_with_binary_operation_of_aggregation_expr" value="SELECT (count(*)+1) as a" db-types="MySQL" />
<sql-case id="select_with_schema_func" value="SELECT schema(), database()" db-types="MySQL" />
<sql-case id="select_sqlmode_ansi_quotes" value='select "id" from "t_order" where "t_order"."id"=10' db-types="MySQL" />