This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
The following commit(s) were added to refs/heads/master by this push:
new 58440b9 [Bug] Left() string function behaves not identically to the
mysql implementation (#6811)
58440b9 is described below
commit 58440b90f0a983f84f3ea06639363c368536a0fb
Author: tianhui5 <[email protected]>
AuthorDate: Fri Oct 15 10:17:21 2021 +0800
[Bug] Left() string function behaves not identically to the mysql
implementation (#6811)
See Fix #6810
---
be/src/exprs/string_functions.cpp | 1 +
be/test/exprs/string_functions_test.cpp | 7 +++++++
2 files changed, 8 insertions(+)
diff --git a/be/src/exprs/string_functions.cpp
b/be/src/exprs/string_functions.cpp
index 233be37..1c95f2f 100644
--- a/be/src/exprs/string_functions.cpp
+++ b/be/src/exprs/string_functions.cpp
@@ -120,6 +120,7 @@ StringVal StringFunctions::substring(FunctionContext*
context, const StringVal&
// string left(string input, int len)
// This behaves identically to the mysql implementation.
StringVal StringFunctions::left(FunctionContext* context, const StringVal&
str, const IntVal& len) {
+ if (len.val >= str.len) return str;
return substring(context, str, 1, len);
}
diff --git a/be/test/exprs/string_functions_test.cpp
b/be/test/exprs/string_functions_test.cpp
index fe894cd..010c1e3 100644
--- a/be/test/exprs/string_functions_test.cpp
+++ b/be/test/exprs/string_functions_test.cpp
@@ -287,6 +287,13 @@ TEST_F(StringFunctionsTest, null_or_empty) {
delete context;
}
+TEST_F(StringFunctionsTest, left) {
+ doris_udf::FunctionContext* context = new doris_udf::FunctionContext();
+
+ ASSERT_EQ(AnyValUtil::from_string(ctx, std::string("")),
+ StringFunctions::left(context, StringVal(""), 10));
+}
+
TEST_F(StringFunctionsTest, substring) {
doris_udf::FunctionContext* context = new doris_udf::FunctionContext();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]