You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2020/04/30 06:18:35 UTC

[GitHub] [incubator-doris] Youngwb commented on a change in pull request #3439: Support append_trailing_char_if_absent function

Youngwb commented on a change in pull request #3439:
URL: https://github.com/apache/incubator-doris/pull/3439#discussion_r417778746



##########
File path: be/src/exprs/string_functions.cpp
##########
@@ -212,6 +212,28 @@ StringVal StringFunctions::rpad(
     }
     return result;
 }
+
+StringVal StringFunctions::append_trailing_char_if_absent(doris_udf::FunctionContext* context,
+        const doris_udf::StringVal& str, const doris_udf::StringVal& trailing_char) {
+    if (str.is_null || trailing_char.is_null) {
+        return StringVal::null();
+    }
+    if (str.len == 0) {
+        return trailing_char;
+    }
+    if (str.ptr[str.len-1] == trailing_char.ptr[0]) {
+        return str;
+    }
+
+    StringVal result(context, str.len + trailing_char.len);
+    if (UNLIKELY(result.is_null)) {

Review comment:
       StringVal will alloc memory by context's FreePool, that may be null. I use this check according to other string_functions. But this check `is_null` may be useless, It can be removed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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