You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2022/07/06 14:51:08 UTC

[doris] branch master updated: [fix] substr('', 1, 5) return empty string instead of null (#10622)

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 8012d63ea0 [fix] substr('', 1, 5) return empty string instead of null (#10622)
8012d63ea0 is described below

commit 8012d63ea027751847826dbcb9114f4153d3a6c7
Author: Dongyang Li <he...@qq.com>
AuthorDate: Wed Jul 6 22:51:02 2022 +0800

    [fix] substr('', 1, 5) return empty string instead of null (#10622)
---
 be/src/vec/functions/function_string.h                 |  4 ++--
 be/test/vec/function/function_string_test.cpp          | 18 +++++++++++++++---
 .../string_functions/test_string_function.out          |  2 +-
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/be/src/vec/functions/function_string.h b/be/src/vec/functions/function_string.h
index 4d4fdc566f..c545223a23 100644
--- a/be/src/vec/functions/function_string.h
+++ b/be/src/vec/functions/function_string.h
@@ -165,9 +165,9 @@ private:
         for (int i = 0; i < size; ++i) {
             auto* raw_str = reinterpret_cast<const unsigned char*>(&chars[offsets[i - 1]]);
             int str_size = offsets[i] - offsets[i - 1] - 1;
-            // return null if start > src.length
+            // return empty string if start > src.length
             if (start[i] > str_size) {
-                StringOP::push_null_string(i, res_chars, res_offsets, null_map);
+                StringOP::push_empty_string(i, res_chars, res_offsets);
                 continue;
             }
             // return "" if len < 0 or str == 0 or start == 0
diff --git a/be/test/vec/function/function_string_test.cpp b/be/test/vec/function/function_string_test.cpp
index 1ed92aabe8..60cb797aae 100644
--- a/be/test/vec/function/function_string_test.cpp
+++ b/be/test/vec/function/function_string_test.cpp
@@ -39,7 +39,12 @@ TEST(function_string_test, function_string_substr_test) {
                 {{std::string("hello word"), -5, 5}, std::string(" word")},
                 {{std::string("hello word"), 1, 12}, std::string("hello word")},
                 {{std::string("HELLO,!^%"), 4, 2}, std::string("LO")},
-                {{std::string(""), 5, 4}, Null()},
+                {{std::string(""), 5, 4}, std::string("")},
+                {{std::string(""), -1, 4}, std::string("")},
+                {{std::string("12"), 3, 4}, std::string("")},
+                {{std::string(""), 0, 4}, std::string("")},
+                {{std::string("123"), 0, 4}, std::string("")},
+                {{std::string("123"), 1, 0}, std::string("")},
                 {{Null(), 5, 4}, Null()}};
 
         check_function<DataTypeString, true>(func_name, input_types, data_set);
@@ -53,7 +58,11 @@ TEST(function_string_test, function_string_substr_test) {
                 {{std::string("hello word"), -5}, std::string(" word")},
                 {{std::string("hello word"), 1}, std::string("hello word")},
                 {{std::string("HELLO,!^%"), 4}, std::string("LO,!^%")},
-                {{std::string(""), 5, 4}, Null()},
+                {{std::string(""), 5}, std::string("")},
+                {{std::string(""), -1}, std::string("")},
+                {{std::string("12"), 3}, std::string("")},
+                {{std::string(""), 0}, std::string("")},
+                {{std::string("123"), 0}, std::string("")},
                 {{Null(), 5, 4}, Null()}};
 
         check_function<DataTypeString, true>(func_name, input_types, data_set);
@@ -82,7 +91,10 @@ TEST(function_string_test, function_string_strleft_test) {
                         {{std::string("hel  lo  "), 5}, std::string("hel  ")},
                         {{std::string("hello word"), 20}, std::string("hello word")},
                         {{std::string("HELLO,!^%"), 7}, std::string("HELLO,!")},
-                        {{std::string(""), 2}, Null()},
+                        {{std::string(""), 2}, std::string("")},
+                        {{std::string(""), -2}, std::string("")},
+                        {{std::string(""), 0}, std::string("")},
+                        {{std::string("123"), 0}, std::string("")},
                         {{Null(), 3}, Null()}};
 
     check_function<DataTypeString, true>(func_name, input_types, data_set);
diff --git a/regression-test/data/query/sql_functions/string_functions/test_string_function.out b/regression-test/data/query/sql_functions/string_functions/test_string_function.out
index d7c33c667e..70c7d33202 100644
--- a/regression-test/data/query/sql_functions/string_functions/test_string_function.out
+++ b/regression-test/data/query/sql_functions/string_functions/test_string_function.out
@@ -207,7 +207,7 @@ bc1
 c1
 
 -- !sql --
-\N
+
 
 -- !sql --
 bc


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org