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 2024/05/08 09:14:12 UTC
(shardingsphere) branch master updated: fix miss column segment from cast and convert function (#31059)
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 11d9c6021ef fix miss column segment from cast and convert function (#31059)
11d9c6021ef is described below
commit 11d9c6021ef6620d2eee2a84e4fa992faea90ba7
Author: Chuxin Chen <ch...@qq.com>
AuthorDate: Wed May 8 17:14:06 2024 +0800
fix miss column segment from cast and convert function (#31059)
* fix miss column segment from cast and convert function
* fix miss column segment from cast and convert function
---
.../visitor/statement/MySQLStatementVisitor.java | 12 +++----
test/it/parser/src/main/resources/case/dml/do.xml | 23 ++++++++++++++
.../parser/src/main/resources/case/dml/insert.xml | 18 ++++++++++-
.../main/resources/case/dml/select-expression.xml | 6 +++-
.../resources/case/dml/select-special-function.xml | 6 +++-
.../parser/src/main/resources/case/dml/select.xml | 37 +++++++++++++++++++---
6 files changed, 86 insertions(+), 16 deletions(-)
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 e5bc2e2e403..40cc9cb90c8 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
@@ -1039,15 +1039,10 @@ public abstract class MySQLStatementVisitor extends MySQLStatementBaseVisitor<AS
@Override
public final ASTNode visitCastFunction(final CastFunctionContext ctx) {
- calculateParameterCount(ctx.expr());
FunctionSegment result = new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.CAST().getText(), getOriginalText(ctx));
for (ExprContext each : ctx.expr()) {
ASTNode expr = visit(each);
- if (expr instanceof ColumnSegment) {
- result.getParameters().add((ColumnSegment) expr);
- } else if (expr instanceof LiteralExpressionSegment) {
- result.getParameters().add((LiteralExpressionSegment) expr);
- }
+ result.getParameters().add((ExpressionSegment) expr);
}
if (null != ctx.castType()) {
result.getParameters().add((DataTypeSegment) visit(ctx.castType()));
@@ -1084,8 +1079,9 @@ public abstract class MySQLStatementVisitor extends MySQLStatementBaseVisitor<AS
@Override
public final ASTNode visitConvertFunction(final ConvertFunctionContext ctx) {
- calculateParameterCount(Collections.singleton(ctx.expr()));
- return new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.CONVERT().getText(), getOriginalText(ctx));
+ FunctionSegment result = new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.CONVERT().getText(), getOriginalText(ctx));
+ result.getParameters().add((ExpressionSegment) visit(ctx.expr()));
+ return result;
}
@Override
diff --git a/test/it/parser/src/main/resources/case/dml/do.xml b/test/it/parser/src/main/resources/case/dml/do.xml
index 3dfcb3a7a00..5fba8bffe32 100644
--- a/test/it/parser/src/main/resources/case/dml/do.xml
+++ b/test/it/parser/src/main/resources/case/dml/do.xml
@@ -55,6 +55,19 @@
<function function-name="FROM_BASE64" start-index="3" stop-index="54" text="FROM_BASE64(CAST((MID(UUID(),20,64)) AS BINARY(55)))">
<parameter>
<function function-name="CAST" start-index="15" stop-index="53" text="CAST((MID(UUID(),20,64)) AS BINARY(55))">
+ <parameter>
+ <function function-name="MID" start-index="21" stop-index="37" text="MID(UUID(),20,64)">
+ <parameter>
+ <function function-name="UUID" start-index="25" stop-index="30" text="UUID()" />
+ </parameter>
+ <parameter>
+ <literal-expression value="20" start-index="32" stop-index="33" />
+ </parameter>
+ <parameter>
+ <literal-expression value="64" start-index="35" stop-index="36" />
+ </parameter>
+ </function>
+ </parameter>
<parameter>
<data-type start-index="43" stop-index="52" value="BINARY" />
</parameter>
@@ -70,6 +83,16 @@
<function function-name="FROM_BASE64" start-index="3" stop-index="45" text="FROM_BASE64(CAST(RIGHT(11,1)AS BINARY(24)))">
<parameter>
<function function-name="CAST" start-index="15" stop-index="44" text="CAST(RIGHT(11,1)AS BINARY(24))">
+ <parameter>
+ <function function-name="RIGHT" start-index="20" stop-index="30" text="RIGHT(11,1)">
+ <parameter>
+ <literal-expression value="11" start-index="26" stop-index="27" />
+ </parameter>
+ <parameter>
+ <literal-expression value="1" start-index="29" stop-index="29" />
+ </parameter>
+ </function>
+ </parameter>
<parameter>
<data-type start-index="34" stop-index="43" value="BINARY" />
</parameter>
diff --git a/test/it/parser/src/main/resources/case/dml/insert.xml b/test/it/parser/src/main/resources/case/dml/insert.xml
index 6a89c32c5a8..5b3061257aa 100644
--- a/test/it/parser/src/main/resources/case/dml/insert.xml
+++ b/test/it/parser/src/main/resources/case/dml/insert.xml
@@ -1486,7 +1486,23 @@
<assignment start-index="51" stop-index="111" literal-stop-index="116">
<column name="status" start-index="51" stop-index="56" />
<assignment-value>
- <function function-name="convert" text="convert(to_base64(aes_encrypt(?, 'key')) USING utf8)" literal-text="convert(to_base64(aes_encrypt('init', 'key')) USING utf8)" start-index="60" stop-index="111" literal-start-index="60" literal-stop-index="116" />
+ <function function-name="convert" text="convert(to_base64(aes_encrypt(?, 'key')) USING utf8)" literal-text="convert(to_base64(aes_encrypt('init', 'key')) USING utf8)" start-index="60" stop-index="111" literal-start-index="60" literal-stop-index="116">
+ <parameter>
+ <function function-name="to_base64" text="to_base64(aes_encrypt(?, 'key'))" literal-text="to_base64(aes_encrypt('init', 'key'))" start-index="68" stop-index="99" literal-start-index="68" literal-stop-index="104">
+ <parameter>
+ <function function-name="aes_encrypt" text="aes_encrypt(?, 'key')" literal-text="aes_encrypt('init', 'key')" start-index="78" stop-index="98" literal-start-index="78" literal-stop-index="103">
+ <parameter>
+ <literal-expression value="init" start-index="85" stop-index="90" literal-start-index="90" literal-stop-index="95" />
+ <parameter-marker-expression parameter-index="2" start-index="90" stop-index="90" />
+ </parameter>
+ <parameter>
+ <literal-expression value="key" start-index="93" stop-index="97" literal-start-index="98" literal-stop-index="102" />
+ </parameter>
+ </function>
+ </parameter>
+ </function>
+ </parameter>
+ </function>
</assignment-value>
</assignment>
</set>
diff --git a/test/it/parser/src/main/resources/case/dml/select-expression.xml b/test/it/parser/src/main/resources/case/dml/select-expression.xml
index c955bb441f5..c5b51bb447b 100644
--- a/test/it/parser/src/main/resources/case/dml/select-expression.xml
+++ b/test/it/parser/src/main/resources/case/dml/select-expression.xml
@@ -48,7 +48,11 @@
<right>
<binary-operation-expression start-index="114" stop-index="165">
<left>
- <function function-name="CONVERT" start-index="114" stop-index="146" text="CONVERT(VARIABLE_VALUE, UNSIGNED)" />
+ <function function-name="CONVERT" start-index="114" stop-index="146" text="CONVERT(VARIABLE_VALUE, UNSIGNED)">
+ <parameter>
+ <column name="VARIABLE_VALUE" start-index="122" stop-index="135" />
+ </parameter>
+ </function>
</left>
<operator>></operator>
<right>
diff --git a/test/it/parser/src/main/resources/case/dml/select-special-function.xml b/test/it/parser/src/main/resources/case/dml/select-special-function.xml
index cc8b648cb10..88548d89186 100644
--- a/test/it/parser/src/main/resources/case/dml/select-special-function.xml
+++ b/test/it/parser/src/main/resources/case/dml/select-special-function.xml
@@ -130,7 +130,11 @@
<projections start-index="7" stop-index="33">
<expression-projection text="CONVERT('2020-10-01', DATE)" start-index="7" stop-index="33">
<expr>
- <function function-name="CONVERT" start-index="7" stop-index="33" text="CONVERT('2020-10-01', DATE)" />
+ <function function-name="CONVERT" start-index="7" stop-index="33" text="CONVERT('2020-10-01', DATE)">
+ <parameter>
+ <literal-expression value="2020-10-01" start-index="15" stop-index="26" />
+ </parameter>
+ </function>
</expr>
</expression-projection>
</projections>
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 2d65a87228c..142f3d2894d 100644
--- a/test/it/parser/src/main/resources/case/dml/select.xml
+++ b/test/it/parser/src/main/resources/case/dml/select.xml
@@ -495,7 +495,11 @@
<projections start-index="7" stop-index="59">
<expression-projection text="CONVERT(TIMESTAMP "2004-01-22 21:45:33" USING latin1)" start-index="7" stop-index="59">
<expr>
- <function start-index="7" stop-index="59" text="CONVERT(TIMESTAMP "2004-01-22 21:45:33" USING latin1)" function-name="CONVERT" />
+ <function start-index="7" stop-index="59" text="CONVERT(TIMESTAMP "2004-01-22 21:45:33" USING latin1)" function-name="CONVERT">
+ <parameter>
+ <common-expression start-index="15" stop-index="45" text="TIMESTAMP"2004-01-22 21:45:33"" />
+ </parameter>
+ </function>
</expr>
</expression-projection>
</projections>
@@ -505,7 +509,11 @@
<projections start-index="7" stop-index="57">
<expression-projection text="CONVERT(TIMESTAMP "2004-01-22 21:45:33", BINARY(4))" start-index="7" stop-index="57">
<expr>
- <function start-index="7" stop-index="57" text="CONVERT(TIMESTAMP "2004-01-22 21:45:33", BINARY(4))" function-name="CONVERT" />
+ <function start-index="7" stop-index="57" text="CONVERT(TIMESTAMP "2004-01-22 21:45:33", BINARY(4))" function-name="CONVERT" >
+ <parameter>
+ <common-expression start-index="15" stop-index="45" text="TIMESTAMP"2004-01-22 21:45:33"" function-name="GROUPING(f1)" />
+ </parameter>
+ </function>
</expr>
</expression-projection>
</projections>
@@ -515,7 +523,11 @@
<projections start-index="7" stop-index="55">
<expression-projection text="CONVERT(TIMESTAMP "2004-01-22 21:45:33", CHAR(4))" start-index="7" stop-index="55">
<expr>
- <function start-index="7" stop-index="55" text="CONVERT(TIMESTAMP "2004-01-22 21:45:33", CHAR(4))" function-name="CONVERT" />
+ <function start-index="7" stop-index="55" text="CONVERT(TIMESTAMP "2004-01-22 21:45:33", CHAR(4))" function-name="CONVERT">
+ <parameter>
+ <common-expression start-index="15" stop-index="45" text="TIMESTAMP"2004-01-22 21:45:33"" />
+ </parameter>
+ </function>
</expr>
</expression-projection>
</projections>
@@ -525,7 +537,11 @@
<projections start-index="7" stop-index="52">
<expression-projection text="CONVERT(TIMESTAMP "2004-01-22 21:45:33", CHAR)" start-index="7" stop-index="52">
<expr>
- <function start-index="7" stop-index="52" text="CONVERT(TIMESTAMP "2004-01-22 21:45:33", CHAR)" function-name="CONVERT" />
+ <function start-index="7" stop-index="52" text="CONVERT(TIMESTAMP "2004-01-22 21:45:33", CHAR)" function-name="CONVERT">
+ <parameter>
+ <common-expression start-index="15" stop-index="45" text="TIMESTAMP"2004-01-22 21:45:33"" />
+ </parameter>
+ </function>
</expr>
</expression-projection>
</projections>
@@ -3805,7 +3821,18 @@
<projections start-index="7" stop-index="63">
<expression-projection text="CONVERT(SUBSTRING(content, 5) , SIGNED)" alias="signed_content" start-index="7" stop-index="63">
<expr>
- <function function-name="CONVERT" start-index="7" stop-index="45" text="CONVERT(SUBSTRING(content, 5) , SIGNED)" />
+ <function function-name="CONVERT" start-index="7" stop-index="45" text="CONVERT(SUBSTRING(content, 5) , SIGNED)">
+ <parameter>
+ <function function-name="SUBSTRING" start-index="15" stop-index="35" text="SUBSTRING(content, 5)">
+ <parameter>
+ <column name="content" start-index="25" stop-index="31" />
+ </parameter>
+ <parameter>
+ <literal-expression value="5" start-index="34" stop-index="34" />
+ </parameter>
+ </function>
+ </parameter>
+ </function>
</expr>
</expression-projection>
</projections>