From 1c14cc65b087c44c209be87bcc75a2e5b743151d Mon Sep 17 00:00:00 2001 From: LiBinfeng Date: Mon, 9 Dec 2024 11:18:50 +0800 Subject: [PATCH] [fix](Planner) fix escape character when used in create view --- .../main/java/org/apache/doris/analysis/StringLiteral.java | 3 +++ .../doris/external/elasticsearch/QueryBuildersTest.java | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/StringLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/StringLiteral.java index 09cb50bb9ed72b..26399ebd3f131f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/StringLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/StringLiteral.java @@ -135,6 +135,9 @@ public boolean isMinValue() { @Override public String toSqlImpl() { + if (value.equals("\\")) { + value = "\\\\"; + } return "'" + value.replaceAll("'", "''") + "'"; } diff --git a/fe/fe-core/src/test/java/org/apache/doris/external/elasticsearch/QueryBuildersTest.java b/fe/fe-core/src/test/java/org/apache/doris/external/elasticsearch/QueryBuildersTest.java index 69eab5198aa214..9ea9c3ce87d90a 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/external/elasticsearch/QueryBuildersTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/external/elasticsearch/QueryBuildersTest.java @@ -99,6 +99,12 @@ public void testBinaryPredicateConvertEsDsl() { QueryBuilders.toEsDsl(stringNeExpr, column2typeMap).toJson()); } + @Test + public void testStringLiteralToSql() { + Expr escape = new StringLiteral("\\"); + Assertions.assertEquals("'\\\\'", escape.toSql()); + } + @Test public void testCompoundPredicateConvertEsDsl() { SlotRef k1 = new SlotRef(null, "k1");