This is an automated email from the ASF dual-hosted git repository.
yiguolei 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 34f43ac781 [bug](like function)fix like '' (empty string) get wrong
result with all rows #14035
34f43ac781 is described below
commit 34f43ac7819c5e237ef6654d6a518dc478cb74e8
Author: Kang <[email protected]>
AuthorDate: Tue Nov 8 08:51:39 2022 +0800
[bug](like function)fix like '' (empty string) get wrong result with all
rows #14035
---
be/src/vec/functions/like.cpp | 7 +++++-
be/test/vec/function/function_like_test.cpp | 6 +++++
.../test_string_function_like_pushdown.out | 26 ++++++++++++++++++++++
.../string_functions/test_string_function_like.out | 24 ++++++++++++++++++++
.../test_string_function_like_pushdown.groovy | 5 +++++
.../test_string_function_like.groovy | 6 ++++-
6 files changed, 72 insertions(+), 2 deletions(-)
diff --git a/be/src/vec/functions/like.cpp b/be/src/vec/functions/like.cpp
index 097352c360..4e96389b81 100644
--- a/be/src/vec/functions/like.cpp
+++ b/be/src/vec/functions/like.cpp
@@ -471,6 +471,11 @@ void FunctionLike::convert_like_pattern(LikeSearchState*
state, const std::strin
std::string* re_pattern) {
re_pattern->clear();
+ if (pattern.empty()) {
+ re_pattern->append("^$");
+ return;
+ }
+
// add ^ to pattern head to match line head
if (pattern.size() > 0 && pattern[0] != '%') {
re_pattern->append("^");
@@ -539,7 +544,7 @@ Status FunctionLike::prepare(FunctionContext* context,
FunctionContext::Function
std::string pattern_str = pattern.to_string();
state->search_state.pattern_str = pattern_str;
std::string search_string;
- if (RE2::FullMatch(pattern_str, LIKE_EQUALS_RE, &search_string)) {
+ if (pattern_str.empty() || RE2::FullMatch(pattern_str, LIKE_EQUALS_RE,
&search_string)) {
remove_escape_character(&search_string);
state->search_state.set_search_string(search_string);
state->function = constant_equals_fn;
diff --git a/be/test/vec/function/function_like_test.cpp
b/be/test/vec/function/function_like_test.cpp
index 2162c4b99e..6e53d220d5 100644
--- a/be/test/vec/function/function_like_test.cpp
+++ b/be/test/vec/function/function_like_test.cpp
@@ -38,6 +38,12 @@ TEST(FunctionLikeTest, like) {
{{std::string("abc"), std::string("a%")}, uint8_t(1)},
{{std::string("bc"), std::string("a%")}, uint8_t(0)},
// equals
+ {{std::string(""), std::string("")}, uint8_t(1)},
+ {{std::string(""), std::string(" ")}, uint8_t(0)},
+ {{std::string(" "), std::string(" ")}, uint8_t(1)},
+ {{std::string(" "), std::string("")}, uint8_t(0)},
+ {{std::string("abc"), std::string("")}, uint8_t(0)},
+ {{std::string("abc"), std::string(" ")}, uint8_t(0)},
{{std::string("abc"), std::string("abc")}, uint8_t(1)},
{{std::string("abc"), std::string("ab")}, uint8_t(0)},
// full regexp match
diff --git
a/regression-test/data/query/sql_functions/string_functions/test_string_function_like_pushdown.out
b/regression-test/data/query/sql_functions/string_functions/test_string_function_like_pushdown.out
index 712b680f96..fc85176126 100644
---
a/regression-test/data/query/sql_functions/string_functions/test_string_function_like_pushdown.out
+++
b/regression-test/data/query/sql_functions/string_functions/test_string_function_like_pushdown.out
@@ -1,4 +1,10 @@
-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !sql --
+
+
+-- !sql --
+
+
-- !sql --
a
@@ -31,6 +37,8 @@ bab
accb
-- !sql --
+
+
ab
accb
b
@@ -39,6 +47,8 @@ bab
bb
-- !sql --
+
+
ab
accb
b
@@ -46,16 +56,22 @@ bab
bb
-- !sql --
+
+
b
ba
bab
bb
-- !sql --
+
+
b
bb
-- !sql --
+
+
a
ab
accb
@@ -64,6 +80,8 @@ bab
bb
-- !sql --
+
+
a
accb
b
@@ -72,6 +90,8 @@ bab
bb
-- !sql --
+
+
a
ab
accb
@@ -80,6 +100,8 @@ ba
bb
-- !sql --
+
+
a
ab
b
@@ -88,6 +110,8 @@ bab
bb
-- !sql --
+
+
a
ab
accb
@@ -99,6 +123,8 @@ bb
-- !sql --
-- !sql --
+0
+0
1 a
1 b
2 bab
diff --git
a/regression-test/data/query_p0/sql_functions/string_functions/test_string_function_like.out
b/regression-test/data/query_p0/sql_functions/string_functions/test_string_function_like.out
index 609fceed20..eec1827d95 100644
---
a/regression-test/data/query_p0/sql_functions/string_functions/test_string_function_like.out
+++
b/regression-test/data/query_p0/sql_functions/string_functions/test_string_function_like.out
@@ -1,4 +1,10 @@
-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !sql --
+
+
+-- !sql --
+
+
-- !sql --
a
@@ -31,6 +37,8 @@ bab
accb
-- !sql --
+
+
ab
accb
b
@@ -39,6 +47,8 @@ bab
bb
-- !sql --
+
+
ab
accb
b
@@ -46,16 +56,22 @@ bab
bb
-- !sql --
+
+
b
ba
bab
bb
-- !sql --
+
+
b
bb
-- !sql --
+
+
a
ab
accb
@@ -64,6 +80,8 @@ bab
bb
-- !sql --
+
+
a
accb
b
@@ -72,6 +90,8 @@ bab
bb
-- !sql --
+
+
a
ab
accb
@@ -80,6 +100,8 @@ ba
bb
-- !sql --
+
+
a
ab
b
@@ -88,6 +110,8 @@ bab
bb
-- !sql --
+
+
a
ab
accb
diff --git
a/regression-test/suites/query/sql_functions/string_functions/test_string_function_like_pushdown.groovy
b/regression-test/suites/query/sql_functions/string_functions/test_string_function_like_pushdown.groovy
index 8e2f450bb2..5dcf8d4a2e 100644
---
a/regression-test/suites/query/sql_functions/string_functions/test_string_function_like_pushdown.groovy
+++
b/regression-test/suites/query/sql_functions/string_functions/test_string_function_like_pushdown.groovy
@@ -31,6 +31,8 @@ suite("test_string_function_like_pushdown", "query") {
"""
sql """
INSERT INTO ${tbName} VALUES
+ (0, ""),
+ (0, " "),
(1, "a"),
(1, "b"),
(2, "bb"),
@@ -39,6 +41,9 @@ suite("test_string_function_like_pushdown", "query") {
(4, "ab"),
(5, "accb");
"""
+ qt_sql "SELECT k FROM ${tbName} WHERE k LIKE \"\" ORDER BY k;"
+ qt_sql "SELECT k FROM ${tbName} WHERE k LIKE \" \" ORDER BY k;"
+
qt_sql "SELECT k FROM ${tbName} WHERE k LIKE \"a\" ORDER BY k;"
qt_sql "SELECT k FROM ${tbName} WHERE k LIKE \"%a\" ORDER BY k;"
qt_sql "SELECT k FROM ${tbName} WHERE k LIKE \"a%\" ORDER BY k;"
diff --git
a/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function_like.groovy
b/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function_like.groovy
index 87bded69a8..717054933e 100644
---
a/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function_like.groovy
+++
b/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function_like.groovy
@@ -29,6 +29,8 @@ suite("test_string_function_like") {
"""
sql """
INSERT INTO ${tbName} VALUES
+ (""),
+ (" "),
("a"),
("b"),
("bb"),
@@ -37,6 +39,8 @@ suite("test_string_function_like") {
("ab"),
("accb");
"""
+ qt_sql "SELECT k FROM ${tbName} WHERE k LIKE \"\" ORDER BY k;"
+ qt_sql "SELECT k FROM ${tbName} WHERE k LIKE \" \" ORDER BY k;"
qt_sql "SELECT k FROM ${tbName} WHERE k LIKE \"a\" ORDER BY k;"
qt_sql "SELECT k FROM ${tbName} WHERE k LIKE \"%a\" ORDER BY k;"
qt_sql "SELECT k FROM ${tbName} WHERE k LIKE \"a%\" ORDER BY k;"
@@ -60,5 +64,5 @@ suite("test_string_function_like") {
qt_sql "SELECT k FROM ${tbName} WHERE k LIKE \"%\" ORDER BY k;"
qt_sql "SELECT k FROM ${tbName} WHERE k NOT LIKE \"%\" ORDER BY k;"
- sql "DROP TABLE ${tbName};"
+ // sql "DROP TABLE ${tbName};"
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]