This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch dev-1.1.2
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/dev-1.1.2 by this push:
new b86f0abb98 [fix] substr('', 1, 5) return empty string instead of null
(#10622)
b86f0abb98 is described below
commit b86f0abb9812a1bdee43f974e81d3dea4e517ec3
Author: Dongyang Li <[email protected]>
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 +++++++++++++++---
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/be/src/vec/functions/function_string.h
b/be/src/vec/functions/function_string.h
index 692fa3fe86..0200adf495 100644
--- a/be/src/vec/functions/function_string.h
+++ b/be/src/vec/functions/function_string.h
@@ -166,9 +166,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 61b1e529bc..d2d42f0d76 100644
--- a/be/test/vec/function/function_string_test.cpp
+++ b/be/test/vec/function/function_string_test.cpp
@@ -42,7 +42,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);
@@ -56,7 +61,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);
@@ -85,7 +94,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);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]