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 efc3286 fix 6753 (#6915)
efc3286 is described below
commit efc328689efd221af5ca1760730dace2a374300b
Author: JingShang Lu <[email protected]>
AuthorDate: Wed Aug 19 14:32:50 2020 +0800
fix 6753 (#6915)
---
.../sql/parser/mysql/visitor/MySQLVisitor.java | 13 +++-----
.../src/test/resources/case/dml/update.xml | 36 ++++++++++++++++++++++
.../test/resources/sql/supported/dml/update.xml | 2 ++
3 files changed, 42 insertions(+), 9 deletions(-)
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/MySQLVisitor.java
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/MySQLVisitor.java
index c99136b..f4192cf 100644
---
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/MySQLVisitor.java
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/MySQLVisitor.java
@@ -29,7 +29,6 @@ import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.BitExpr
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.BitValueLiteralsContext;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.BooleanLiteralsContext;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.BooleanPrimaryContext;
-import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CaseExpressionContext;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CastFunctionContext;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CharFunctionContext;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ColumnNameContext;
@@ -392,7 +391,7 @@ public abstract class MySQLVisitor extends
MySQLStatementBaseVisitor<ASTNode> {
return new SubqueryExpressionSegment((SubquerySegment) astNode);
}
if (astNode instanceof OtherLiteralValue) {
- return new
CommonExpressionSegment(context.getStart().getStartIndex(),
context.getStop().getStopIndex(), context.getText());
+ return new
CommonExpressionSegment(context.getStart().getStartIndex(),
context.getStop().getStopIndex(), ((OtherLiteralValue) astNode).getValue());
}
return astNode;
}
@@ -587,7 +586,9 @@ public abstract class MySQLVisitor extends
MySQLStatementBaseVisitor<ASTNode> {
private ASTNode visitRemainSimpleExpr(final SimpleExprContext ctx) {
if (null != ctx.caseExpression()) {
- return visit(ctx.caseExpression());
+ visit(ctx.caseExpression());
+ String text = ctx.start.getInputStream().getText(new
Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
+ return new OtherLiteralValue(text);
}
for (ExprContext each : ctx.expr()) {
visit(each);
@@ -607,12 +608,6 @@ public abstract class MySQLVisitor extends
MySQLStatementBaseVisitor<ASTNode> {
}
@Override
- public final ASTNode visitCaseExpression(final CaseExpressionContext ctx) {
- String text = ctx.start.getInputStream().getText(new
Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
- return new OtherLiteralValue(text);
- }
-
- @Override
public final ASTNode visitDataTypeName(final DataTypeNameContext ctx) {
return new KeywordValue(ctx.getText());
}
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/case/dml/update.xml
b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/case/dml/update.xml
index 60356d8..2516039 100644
---
a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/case/dml/update.xml
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/case/dml/update.xml
@@ -447,4 +447,40 @@
</and-predicate>
</where>
</update>
+
+ <update sql-case-id="update_with_case_when" parameters="3, 2, 4, 2, 10, 2,
3, 'll', 4, 'll', 10, 'll', 3, '2020-08-10T17:15:25.979+0800', 'jd'">
+ <table name="stock_freeze_detail" start-index="7" stop-index="25" />
+ <set start-index="27" stop-index="230" literal-stop-index="270"
literal-start-index="27" >
+ <assignment start-index="31" stop-index="106"
literal-start-index="31" literal-stop-index="107">
+ <column name="row_status" start-index="31" stop-index="40" />
+ <assignment-value>
+ <common-expression text="case WHEN (id=?) THEN ? WHEN
(id=?) THEN ? WHEN (id=?) THEN ? end" literal-text="case WHEN (id=3) THEN 2
WHEN (id=4) THEN 2 WHEN (id=10) THEN 2 end" start-index="42" stop-index="106"
literal-start-index="42" literal-stop-index="107"/>
+ </assignment-value>
+ </assignment>
+ <assignment start-index="113" stop-index="189"
literal-start-index="114" literal-stop-index="200">
+ <column name="update_user" start-index="113" stop-index="123"
literal-start-index="114" literal-stop-index="124"/>
+ <assignment-value>
+ <common-expression text="case WHEN (id=?) THEN ? WHEN
(id=?) THEN ? WHEN (id=?) THEN ? end" literal-text="case WHEN (id=3) THEN 'll'
WHEN (id=4) THEN 'll' WHEN (id=10) THEN 'll' end" start-index="125"
stop-index="189" literal-start-index="126" literal-stop-index="200"/>
+ </assignment-value>
+ </assignment>
+ <assignment start-index="192" stop-index="230"
literal-start-index="203" literal-stop-index="270">
+ <column name="update_time" start-index="192" stop-index="202"
literal-start-index="203" literal-stop-index="213" />
+ <assignment-value>
+ <common-expression text="case WHEN (id=?) THEN ? end"
literal-text="case WHEN (id=3) THEN '2020-08-10T17:15:25.979+0800' end"
start-index="204" stop-index="230" literal-start-index="215"
literal-stop-index="270"/>
+ </assignment-value>
+ </assignment>
+ </set>
+ <where start-index="232" stop-index="251" literal-start-index="272"
literal-stop-index="294">
+ <and-predicate>
+ <predicate start-index="239" stop-index="251"
literal-start-index="279" literal-stop-index="294">
+ <column-left-value name="tenant_id" start-index="239"
stop-index="247" literal-start-index="279" literal-stop-index="287" />
+ <operator type="=" />
+ <compare-right-value>
+ <parameter-marker-expression value="14"
start-index="251" stop-index="251"/>
+ <literal-expression value="jd"
literal-start-index="291" literal-stop-index="294"/>
+ </compare-right-value>
+ </predicate>
+ </and-predicate>
+ </where>
+ </update>
</sql-parser-test-cases>
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/supported/dml/update.xml
b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/supported/dml/update.xml
index 31c2523..342b3af 100644
---
a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/supported/dml/update.xml
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/supported/dml/update.xml
@@ -29,4 +29,6 @@
<sql-case id="update_with_set_calculation" value="UPDATE t_order SET
status = status - ? WHERE order_id = ? AND user_id = ?" />
<sql-case id="update_with_where_calculation" value="UPDATE t_order SET
status = ? WHERE order_id = order_id - ? AND user_id = ?" />
<sql-case id="update_with_column_equal_column" value="update t_order set
order_id = order_id, status = 'init' where order_id = order_id AND order_id =
?" db-types="MySQL"/>
+ <sql-case id="update_with_case_when" value="update stock_freeze_detail set
row_status=case WHEN (id=?) THEN ? WHEN (id=?) THEN ? WHEN (id=?) THEN ? end,
+ update_user=case WHEN (id=?) THEN ? WHEN (id=?) THEN ? WHEN (id=?) THEN ?
end, update_time=case WHEN (id=?) THEN ? end where tenant_id = ?"
db-types="MySQL"/>
</sql-cases>