You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2023/12/18 02:18:27 UTC
(shardingsphere) branch master updated: Fix mysql notExpression ClassCastException (#29417)
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 c46a3fa66ed Fix mysql notExpression ClassCastException (#29417)
c46a3fa66ed is described below
commit c46a3fa66ed871f7f5a89a50cb304e36d71522c7
Author: niu niu <zi...@aliyun.com>
AuthorDate: Mon Dec 18 10:18:19 2023 +0800
Fix mysql notExpression ClassCastException (#29417)
---
.../visitor/statement/MySQLStatementVisitor.java | 2 +-
.../parser/src/main/resources/case/dml/select.xml | 145 +++++++++++++++++++++
.../main/resources/sql/supported/dml/select.xml | 1 +
3 files changed, 147 insertions(+), 1 deletion(-)
diff --git a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/MySQLStatementVisitor.java b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/MySQLStatementVisitor.java
index de19a3cb4d0..df103b18f87 100644
--- a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/MySQLStatementVisitor.java
+++ b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/MySQLStatementVisitor.java
@@ -1770,7 +1770,7 @@ public abstract class MySQLStatementVisitor extends MySQLStatementBaseVisitor<AS
return projection;
}
if (projection instanceof CaseWhenExpression || projection instanceof VariableSegment || projection instanceof BetweenExpression || projection instanceof InExpression
- || projection instanceof CollateExpression) {
+ || projection instanceof CollateExpression || projection instanceof NotExpression) {
return createExpressionProjectionSegment(ctx, alias, projection);
}
LiteralExpressionSegment column = (LiteralExpressionSegment) projection;
diff --git a/test/it/parser/src/main/resources/case/dml/select.xml b/test/it/parser/src/main/resources/case/dml/select.xml
index 54ba480dd3a..859271a97e1 100644
--- a/test/it/parser/src/main/resources/case/dml/select.xml
+++ b/test/it/parser/src/main/resources/case/dml/select.xml
@@ -7536,4 +7536,149 @@
</expr>
</where>
</select>
+
+ <select sql-case-id="select_not_expression">
+ <projections start-index="7" stop-index="75">
+ <expression-projection text="!0" start-index="7" stop-index="8">
+ <expr>
+ <not-expression start-index="7" stop-index="8">
+ <expr>
+ <literal-expression value="0" start-index="8" stop-index="8" />
+ </expr>
+ </not-expression>
+ </expr>
+ </expression-projection>
+ <expression-projection text="NOT 0=1" start-index="10" stop-index="16">
+ <expr>
+ <binary-operation-expression start-index="10" stop-index="16">
+ <left>
+ <not-expression start-index="10" stop-index="14">
+ <expr>
+ <literal-expression value="0" start-index="14" stop-index="14" />
+ </expr>
+ </not-expression>
+ </left>
+ <right>
+ <literal-expression value="1" start-index="16" stop-index="16" />
+ </right>
+ <operator>=</operator>
+ </binary-operation-expression>
+ </expr>
+ </expression-projection>
+ <expression-projection text="!(0=0)" start-index="18" stop-index="23">
+ <expr>
+ <not-expression start-index="18" stop-index="23">
+ <expr>
+ <binary-operation-expression start-index="20" stop-index="22">
+ <left>
+ <literal-expression value="0" start-index="20" stop-index="20" />
+ </left>
+ <right>
+ <literal-expression value="0" start-index="22" stop-index="22" />
+ </right>
+ <operator>=</operator>
+ </binary-operation-expression>
+ </expr>
+ </not-expression>
+ </expr>
+ </expression-projection>
+ <expression-projection text="1 AND 1" start-index="25" stop-index="31">
+ <expr>
+ <binary-operation-expression start-index="25" stop-index="31">
+ <left>
+ <literal-expression value="1" start-index="25" stop-index="25" />
+ </left>
+ <right>
+ <literal-expression value="1" start-index="31" stop-index="31" />
+ </right>
+ <operator>AND</operator>
+ </binary-operation-expression>
+ </expr>
+ </expression-projection>
+ <expression-projection text="1 && 0" start-index="33" stop-index="38">
+ <expr>
+ <binary-operation-expression start-index="33" stop-index="38">
+ <left>
+ <literal-expression value="1" start-index="33" stop-index="33" />
+ </left>
+ <right>
+ <literal-expression value="0" start-index="38" stop-index="38" />
+ </right>
+ <operator>&&</operator>
+ </binary-operation-expression>
+ </expr>
+ </expression-projection>
+ <expression-projection text="0 OR 1" start-index="40" stop-index="45">
+ <expr>
+ <binary-operation-expression start-index="40" stop-index="45">
+ <left>
+ <literal-expression value="0" start-index="40" stop-index="40" />
+ </left>
+ <right>
+ <literal-expression value="1" start-index="45" stop-index="45" />
+ </right>
+ <operator>OR</operator>
+ </binary-operation-expression>
+ </expr>
+ </expression-projection>
+ <expression-projection text="1 || NULL" start-index="47" stop-index="55">
+ <expr>
+ <binary-operation-expression start-index="47" stop-index="55">
+ <left>
+ <literal-expression value="1" start-index="47" stop-index="47" />
+ </left>
+ <right>
+ <literal-expression value="null" start-index="52" stop-index="55" />
+ </right>
+ <operator>||</operator>
+ </binary-operation-expression>
+ </expr>
+ </expression-projection>
+ <expression-projection text="1=1 or 1=1 and 1=0" start-index="58" stop-index="75">
+ <expr>
+ <binary-operation-expression start-index="58" stop-index="75">
+ <left>
+ <binary-operation-expression start-index="58" stop-index="60">
+ <left>
+ <literal-expression value="1" start-index="58" stop-index="58" />
+ </left>
+ <right>
+ <literal-expression value="1" start-index="60" stop-index="60" />
+ </right>
+ <operator>=</operator>
+ </binary-operation-expression>
+ </left>
+ <right>
+ <binary-operation-expression start-index="65" stop-index="75">
+ <left>
+ <binary-operation-expression start-index="65" stop-index="67">
+ <left>
+ <literal-expression value="1" start-index="65" stop-index="65" />
+ </left>
+ <right>
+ <literal-expression value="1" start-index="67" stop-index="67" />
+ </right>
+ <operator>=</operator>
+ </binary-operation-expression>
+ </left>
+ <right>
+ <binary-operation-expression start-index="73" stop-index="75">
+ <left>
+ <literal-expression value="1" start-index="73" stop-index="73" />
+ </left>
+ <right>
+ <literal-expression value="0" start-index="75" stop-index="75" />
+ </right>
+ <operator>=</operator>
+ </binary-operation-expression>
+ </right>
+ <operator>and</operator>
+ </binary-operation-expression>
+ </right>
+ <operator>or</operator>
+ </binary-operation-expression>
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
</sql-parser-test-cases>
diff --git a/test/it/parser/src/main/resources/sql/supported/dml/select.xml b/test/it/parser/src/main/resources/sql/supported/dml/select.xml
index 762e913b321..885b7d41f48 100644
--- a/test/it/parser/src/main/resources/sql/supported/dml/select.xml
+++ b/test/it/parser/src/main/resources/sql/supported/dml/select.xml
@@ -231,4 +231,5 @@
<sql-case id="select_wm_concat_function4" value="SELECT NAME,WM_CONCAT(DECODE(SUBSTR((TO_CHAR(NAME)),0,1),'.','0'||TO_CHAR(NAME),TO_CHAR(NAME))) WM_NAME FROM TEST_TABLE WHERE NAME ='TEST' GROUP BY NAME" db-types="Oracle" />
<sql-case id="select_with_user_updatable_columns" value="SELECT column_name, updatable FROM user_updatable_columns WHERE table_name = 'LOCATIONS_VIEW' ORDER BY column_name, updatable" db-types="Oracle" />
<sql-case id="select_with_script_variables" value="SELECT x.$(ColumnName) FROM Person.Person x WHERE x.BusinessEntityID > 5" db-types="SQLServer" />
+ <sql-case id="select_not_expression" value="select !0,NOT 0=1,!(0=0),1 AND 1,1 && 0,0 OR 1,1 || NULL, 1=1 or 1=1 and 1=0" db-types="MySQL" />
</sql-cases>