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 2f63999066e [fix](Nereids): Preserve `""` in single quote strings and
`''` in double quote strings. (#27959)
2f63999066e is described below
commit 2f63999066e1d6278afebc43d01a532f5b46577a
Author: 谢健 <[email protected]>
AuthorDate: Tue Dec 5 12:30:03 2023 +0800
[fix](Nereids): Preserve `""` in single quote strings and `''` in double
quote strings. (#27959)
---
.../apache/doris/nereids/parser/LogicalPlanBuilder.java | 8 +++++++-
.../org/apache/doris/statistics/util/StatisticsUtil.java | 3 +--
.../apache/doris/statistics/util/StatisticsUtilTest.java | 14 +++++++-------
.../data/nereids_syntax_p0/one_row_relation.out | 6 ++++++
.../suites/nereids_syntax_p0/one_row_relation.groovy | 2 ++
5 files changed, 23 insertions(+), 10 deletions(-)
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 45a49ba798f..c3eb5c5a18b 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
@@ -1935,7 +1935,13 @@ public class LogicalPlanBuilder extends
DorisParserBaseVisitor<Object> {
public Literal visitStringLiteral(StringLiteralContext ctx) {
String txt = ctx.STRING_LITERAL().getText();
String s = txt.substring(1, txt.length() - 1);
- s = s.replace("''", "'").replace("\"\"", "\"");
+ if (txt.charAt(0) == '\'') {
+ // for single quote string, '' should be converted to '
+ s = s.replace("''", "'");
+ } else if (txt.charAt(0) == '"') {
+ // for double quote string, "" should be converted to "
+ s = s.replace("\"\"", "\"");
+ }
if (!SqlModeHelper.hasNoBackSlashEscapes()) {
s = LogicalPlanBuilderAssistant.escapeBackSlash(s);
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/statistics/util/StatisticsUtil.java
b/fe/fe-core/src/main/java/org/apache/doris/statistics/util/StatisticsUtil.java
index 99acaf7ca0f..d5bdf8bf053 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/statistics/util/StatisticsUtil.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/statistics/util/StatisticsUtil.java
@@ -789,8 +789,7 @@ public class StatisticsUtil {
return null;
}
return str.replace("'", "''")
- .replace("\\", "\\\\")
- .replace("\"", "\"\"");
+ .replace("\\", "\\\\");
}
public static boolean isExternalTable(String catalogName, String dbName,
String tblName) {
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/statistics/util/StatisticsUtilTest.java
b/fe/fe-core/src/test/java/org/apache/doris/statistics/util/StatisticsUtilTest.java
index c827a7d1690..724e0363833 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/statistics/util/StatisticsUtilTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/statistics/util/StatisticsUtilTest.java
@@ -34,9 +34,9 @@ import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Base64;
-public class StatisticsUtilTest {
+class StatisticsUtilTest {
@Test
- public void testConvertToDouble() {
+ void testConvertToDouble() {
try {
//test DATE
double date1 = StatisticsUtil.convertToDouble(Type.DATE,
"1990-01-01");
@@ -80,7 +80,7 @@ public class StatisticsUtilTest {
}
@Test
- public void testInAnalyzeTime1() {
+ void testInAnalyzeTime1() {
new MockUp<StatisticsUtil>() {
@Mock
@@ -99,7 +99,7 @@ public class StatisticsUtilTest {
}
@Test
- public void testInAnalyzeTime2() {
+ void testInAnalyzeTime2() {
new MockUp<StatisticsUtil>() {
@Mock
@@ -119,7 +119,7 @@ public class StatisticsUtilTest {
@Test
- public void testEncodeValue() throws Exception {
+ void testEncodeValue() throws Exception {
Assertions.assertEquals("NULL", StatisticsUtil.encodeValue(null, 0));
ResultRow row = new ResultRow(null);
@@ -144,10 +144,10 @@ public class StatisticsUtilTest {
}
@Test
- public void testEscape() {
+ void testEscape() {
// \'"
String origin = "\\'\"";
// \\''""
- Assertions.assertEquals("\\\\''\"\"",
StatisticsUtil.escapeSQL(origin));
+ Assertions.assertEquals("\\\\''\"", StatisticsUtil.escapeSQL(origin));
}
}
diff --git a/regression-test/data/nereids_syntax_p0/one_row_relation.out
b/regression-test/data/nereids_syntax_p0/one_row_relation.out
index fc645c3920b..ef715766007 100644
--- a/regression-test/data/nereids_syntax_p0/one_row_relation.out
+++ b/regression-test/data/nereids_syntax_p0/one_row_relation.out
@@ -5,3 +5,9 @@ A'B A''B A''B
-- !string2 --
A"B A""B
+-- !string3 --
+A""B A""B
+
+-- !string4 --
+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 0259bc5940f..b9a43ac54de 100644
--- a/regression-test/suites/nereids_syntax_p0/one_row_relation.groovy
+++ b/regression-test/suites/nereids_syntax_p0/one_row_relation.groovy
@@ -34,4 +34,6 @@ suite("one_row_relation") {
qt_string1 """ select 'A''B', 'A''''B', 'A\\'\\'B', ''; """
qt_string2 """ select "A""B", "A\\"\\"B", ""; """
+ qt_string3 """ select 'A""B', 'A\\"\\"B'; """
+ qt_string4 """ select "A''B", "A\\'\\'B"; """
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]