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 4a16caeaa84 Fix CONVERT mysql function (#26900)
4a16caeaa84 is described below
commit 4a16caeaa84015067d5899ea4695a62501e47fb5
Author: niu niu <[email protected]>
AuthorDate: Thu Jul 13 18:47:17 2023 +0800
Fix CONVERT mysql function (#26900)
---
.../src/main/antlr4/imports/mysql/BaseRule.g4 | 17 +++++++--
.../mysql/visitor/format/MySQLFormatVisitor.java | 2 +-
.../parser/src/main/resources/case/dml/select.xml | 40 ++++++++++++++++++++++
.../main/resources/sql/supported/dml/select.xml | 4 +++
4 files changed, 59 insertions(+), 4 deletions(-)
diff --git a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4
b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4
index 7d8773f9d2d..56a065269b8 100644
--- a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4
+++ b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4
@@ -91,7 +91,7 @@ numberLiterals
;
temporalLiterals
- : (DATE | TIME | TIMESTAMP) SINGLE_QUOTED_TEXT
+ : (DATE | TIME | TIMESTAMP) textString
;
hexadecimalLiterals
@@ -998,8 +998,19 @@ frameBetween
;
specialFunction
- : groupConcatFunction | windowFunction | castFunction | convertFunction |
positionFunction | substringFunction | extractFunction
- | charFunction | trimFunction | weightStringFunction | valuesFunction |
currentUserFunction | groupingFunction
+ : castFunction
+ | convertFunction
+ | currentUserFunction
+ | charFunction
+ | extractFunction
+ | groupConcatFunction
+ | positionFunction
+ | substringFunction
+ | trimFunction
+ | valuesFunction
+ | weightStringFunction
+ | windowFunction
+ | groupingFunction
;
currentUserFunction
diff --git
a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/format/MySQLFormatVisitor.java
b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/format/MySQLFormatVisitor.java
index 11f318615ce..008f2846458 100644
---
a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/format/MySQLFormatVisitor.java
+++
b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/format/MySQLFormatVisitor.java
@@ -723,7 +723,7 @@ public final class MySQLFormatVisitor extends
MySQLStatementBaseVisitor<String>
@Override
public String visitTemporalLiterals(final TemporalLiteralsContext ctx) {
visit(ctx.getChild(0));
- formatPrint(ctx.SINGLE_QUOTED_TEXT().getText());
+ formatPrint(ctx.textString().getText());
return formattedSQL.toString();
}
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 a8b286cbfa9..489313c0c72 100644
--- a/test/it/parser/src/main/resources/case/dml/select.xml
+++ b/test/it/parser/src/main/resources/case/dml/select.xml
@@ -71,6 +71,46 @@
</order-by>
</select>
+ <select sql-case-id="select_convert_function1">
+ <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" />
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
+
+ <select sql-case-id="select_convert_function2">
+ <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" />
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
+
+ <select sql-case-id="select_convert_function3">
+ <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" />
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
+
+ <select sql-case-id="select_convert_function4">
+ <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" />
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
+
<select sql-case-id="select_with_exist_in">
<projections start-index="7" stop-index="93">
<expression-projection text="+0
IN(0b111111111111111111111111111111111111111111111111111,rpad(1.0,2048,1),32767.1)"
start-index="7" stop-index="93">
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 5033668e4e7..8c4afc8e6d5 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
@@ -19,6 +19,10 @@
<sql-cases>
<sql-case id="select_with_hex_function" value="SELECT HEX(_binary 0x0003
<< (_binary 0x38 | 0x38))" db-types="MySQL" />
<sql-case id="select_distinct_with_grouping_function" value="SELECT
DISTINCT f1 FROM t1 GROUP BY f1 WITH ROLLUP ORDER BY f1,
ANY_VALUE(GROUPING(f1))" db-types="MySQL" />
+ <sql-case id="select_convert_function1" value="SELECT CONVERT(TIMESTAMP
"2004-01-22 21:45:33" USING latin1)" db-types="MySQL" />
+ <sql-case id="select_convert_function2" value="SELECT CONVERT(TIMESTAMP
"2004-01-22 21:45:33", BINARY(4))" db-types="MySQL" />
+ <sql-case id="select_convert_function3" value="SELECT CONVERT(TIMESTAMP
"2004-01-22 21:45:33", CHAR(4))" db-types="MySQL" />
+ <sql-case id="select_convert_function4" value="SELECT CONVERT(TIMESTAMP
"2004-01-22 21:45:33", CHAR)" db-types="MySQL" />
<sql-case id="select_with_exist_in" value="SELECT (+0
IN(0b111111111111111111111111111111111111111111111111111,rpad(1.0,2048,1),32767.1))"
db-types="MySQL" />
<sql-case id="select_constant_without_table" value="SELECT 1 as a"
db-types="MySQL, PostgreSQL,openGauss, SQLServer" />
<sql-case id="select_with_operator_ilike" value="SELECT id from t_order
where name !~ '^pg_toast'" db-types="PostgreSQL,openGauss" />