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 010ae43dc3..1b035d96f7 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 49209dcd54..0fb047abee 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 { 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 0000000000..fc645c3920 --- /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 e389960e79..0259bc5940 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", ""; """ }