This is an automated email from the ASF dual-hosted git repository.
jakevin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new d7d284b4f89 [fix](Nereids) fix `''` and `""` in string literal (#25752)
d7d284b4f89 is described below
commit d7d284b4f89bba958dc646ac1539a56fc2a44270
Author: 谢健 <[email protected]>
AuthorDate: Thu Oct 26 11:18:21 2023 +0800
[fix](Nereids) fix `''` and `""` in string literal (#25752)
'' represents ' in sql standard
"" represents " in sql standard
---
fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4 | 4 ++--
.../java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java | 4 +++-
regression-test/data/nereids_syntax_p0/one_row_relation.out | 7 +++++++
regression-test/suites/nereids_syntax_p0/one_row_relation.groovy | 3 +++
4 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4
b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4
index 010ae43dc3c..1b035d96f7c 100644
--- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4
+++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4
@@ -565,8 +565,8 @@ ATSIGN: '@';
DOUBLEATSIGN: '@@';
STRING_LITERAL
- : '\'' ( ~('\''|'\\') | ('\\' .) )* '\''
- | '"' ( ~('"'|'\\') | ('\\' .) )* '"'
+ : '\'' ('\\'. | '\'\'' | ~('\'' | '\\'))* '\''
+ | '"' ( '\\'. | '""' | ~('"'| '\\') )* '"'
| 'R\'' (~'\'')* '\''
| 'R"'(~'"')* '"'
;
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
index 49209dcd54e..0fb047abee3 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
@@ -1721,7 +1721,9 @@ public class LogicalPlanBuilder extends
DorisParserBaseVisitor<Object> {
public Literal visitStringLiteral(StringLiteralContext ctx) {
// TODO: add unescapeSQLString.
String txt = ctx.STRING_LITERAL().getText();
- String s =
LogicalPlanBuilderAssistant.escapeBackSlash(txt.substring(1, txt.length() - 1));
+ String s = txt.substring(1, txt.length() - 1);
+ s = s.replace("''", "'").replace("\"\"", "\"");
+ s = LogicalPlanBuilderAssistant.escapeBackSlash(s);
return new VarcharLiteral(s);
}
diff --git a/regression-test/data/nereids_syntax_p0/one_row_relation.out
b/regression-test/data/nereids_syntax_p0/one_row_relation.out
new file mode 100644
index 00000000000..fc645c3920b
--- /dev/null
+++ b/regression-test/data/nereids_syntax_p0/one_row_relation.out
@@ -0,0 +1,7 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !string1 --
+A'B A''B A''B
+
+-- !string2 --
+A"B A""B
+
diff --git a/regression-test/suites/nereids_syntax_p0/one_row_relation.groovy
b/regression-test/suites/nereids_syntax_p0/one_row_relation.groovy
index e389960e79e..0259bc5940f 100644
--- a/regression-test/suites/nereids_syntax_p0/one_row_relation.groovy
+++ b/regression-test/suites/nereids_syntax_p0/one_row_relation.groovy
@@ -31,4 +31,7 @@ suite("one_row_relation") {
)a"""
result([[100, "abc", "ab", "de", null]])
}
+
+ qt_string1 """ select 'A''B', 'A''''B', 'A\\'\\'B', ''; """
+ qt_string2 """ select "A""B", "A\\"\\"B", ""; """
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]